1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Need an Hand on this Form Script - Quick Fix

Discussion in 'Programming' started by stimpsy, May 30, 2012.

  1. #1
    Hello,

    I have the following form on my site:

    <script type="text/javascript">
    /* <![CDATA[ */
    function sub() {
    window.location.href = site;
    }
    function goTo(URL) {
    site = URL;
    }
    /* ]]> */
    </script>

    <form name="frmSite">
    <div class="row clearfix"><input class="ccheckbox" type="radio" name="site" onchange="if(this.checked){goTo('http://www.google.com')}" />Créer une entreprise</div>
    <div class="row clearfix"><input class="ccheckbox" type="radio" name="site" onchange="if(this.checked){goTo('http://www.google.com')}" />Acquérir une entreprise existante</div>
    <div class="row clearfix"><input class="ccheckbox" type="radio" name="site"onchange="if(this.checked){goTo('http://www.google.com')}" /> Devenir associé dans une entreprise</div>
    <div class="row clearfix"><input type="image" alt="Soumettre" id="ssubmit" src="http://www.test.com/commentcer.png" value="Submit" onclick="sub()" /></div>
    </form>

    -----------

    When I use a Submit button, instead of a Submit image, I am able to send the visitor to a different page based on his selection. However, when I use an image, such as in this case, the redirect does not work and instead I have something like this loading:http://www.url.com/?site=on&x=73&y=21...where I guess X and Y are coordinates or something...i have no idea where they come from..

    Do you by any chance know what I should change to make this form work with an image submit instead of a button submit? I suspect its in the Javascript..?
     
    stimpsy, May 30, 2012 IP
  2. stimpsy

    stimpsy Well-Known Member

    Messages:
    468
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    138
    #2
    I can pay $10 for the fix if anyone is interested..!
     
    stimpsy, May 30, 2012 IP
  3. NetStar

    NetStar Notable Member

    Messages:
    2,471
    Likes Received:
    541
    Best Answers:
    21
    Trophy Points:
    245
    #3
    At quick glance (untested)... the "site" variable is exclusive to the goTo() function and cannot be accessed from the sub() function. If you would like to use the "site" variable in multiple functions declare the variable outside of the function. Like so:

    var site;

    function blah1() {}
    function blah2() {}

    But looking over your code you don't have a use for sub() at all. And btw I wouldn't name your functions goto() and sub(). It looks confusing since those can be private functions in standard programming languages.

    You could use the following:

    function redirectTo(URL) {
    window.location.href = URL;
    }
     
    NetStar, May 30, 2012 IP