Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    Regular Coder tpeck's Avatar
    Join Date
    Oct 2002
    Location
    Sydney, Australia
    Posts
    884
    Thanks
    53
    Thanked 6 Times in 5 Posts

    checking a form and sending off to one of two urls

    I just can't see what I am doing wrong, but this form gives a var choice undefined.

    Code:
    <html>
    <head>
    <script type="text/javascript">
    function check_form(){
    var choice = (document.myform.status.value);
    alert(choice);
    if (choice=="student"){
    parent.window.location.href=('http://www.mysite/index1.html'); return false;
    }
    else if (choice=="tutor"){
    parent.window.location.href=('http://www.mysite/index2.html'); return false;
    }}
    </script>
    </head>
    
    <body>
    
    <form name="myform" method="post" onsubmit="return check_form()" action="" />
    	<input type="checkbox" name="status" value="student" /> Student
    	<input type="checkbox" name="status" value="tutor" /> Tutor
    	<input type="image" src="img/enter.gif" width="60" height="38" border="0" value="submit">
    </form>
    
    </body>
    </html>
    Something's wrong - I can't fathom it. Something obvious I guess...
    The difference between genius and stupidity is that genius has its limits. (Albert Einstein)

  • #2
    New to the CF scene
    Join Date
    Feb 2014
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Add

    Code:
    var choice = '';
    Above

    Code:
    var choice = (document.myform.status.value);

  • #3
    Regular Coder tpeck's Avatar
    Join Date
    Oct 2002
    Location
    Sydney, Australia
    Posts
    884
    Thanks
    53
    Thanked 6 Times in 5 Posts
    Thanks, but it is still not performing...
    The difference between genius and stupidity is that genius has its limits. (Albert Einstein)

  • #4
    Regular Coder tpeck's Avatar
    Join Date
    Oct 2002
    Location
    Sydney, Australia
    Posts
    884
    Thanks
    53
    Thanked 6 Times in 5 Posts
    it's to do with the names being the same - should be:

    <input type="checkbox" name="status1" value="student" /> Student
    <input type="checkbox" name="status2" value="tutor" /> Tutor
    But how do I check for which one of the checkboxes has been selected? Maybe I should use radio buttons?
    The difference between genius and stupidity is that genius has its limits. (Albert Einstein)

  • #5
    Regular Coder tpeck's Avatar
    Join Date
    Oct 2002
    Location
    Sydney, Australia
    Posts
    884
    Thanks
    53
    Thanked 6 Times in 5 Posts
    In the end I used radio buttons and onClicks:

    <form name="myform" method="post" action="" />
    <input type="radio" name="status" id="S" value="student" onClick="goTo('http://www.mysite.com/index1.html')" checked /> <label for="S"><span class="hand">Student</span></label>
    <input type="radio" name="status" id="T" value="tutor" onClick="goTo('http://www.mysite.com/index2.html')" /> <label for="T" class-"hand"><span class="hand">Tutor</span></label>
    The difference between genius and stupidity is that genius has its limits. (Albert Einstein)

  • #6
    Senior Coder
    Join Date
    Aug 2010
    Location
    High Point, NC
    Posts
    3,338
    Thanks
    5
    Thanked 363 Times in 360 Posts
    You could also use data attributes and then get the val of the data attribute in your js. I dislike inline js. lol
    Teed


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •