SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    Aug 2007
    Posts
    18
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    simple conditional statement HELP needed.

    Hello,
    I am not a javascripter however I have a simple need to a yes no question before someone can fill out a form. Bloew is what I have. If they click yes I'll take them to the form, if no then I will redirect them to a different page. I can not get it to work. Any help would be appreciated.

    Code:
    <script type="text/javascript">
    <!--
    function valbutton(thisform) {
    
    if(thisform.myradiobutton.checked==true){
    
                    var radiovalue = thisform.myradiobutton.value;
    
                    if(radiovalue == "yes"){
    
                    window.location = "http://www.google.com/";
    
                    } else {
    
                    window.location = "http://www.gmail.com/";
                    }
    }
       return false;
    }
    //-->
    </script>
    <form name="myform" method="POST">
    
    <input type="radio" value="yes" name="myradiobutton" />yes<br />
    
    <input type="radio" value="no" name="myradiobutton" />no<br />
    
    <input type="submit" name="submitit" onclick="valbutton(myform);" value="Validate" />
    </form>
    Thanks
    Tim

  2. #2
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,862
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    thisform.myradiobutton is an array
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  3. #3
    SitePoint Wizard Stomme poes's Avatar
    Join Date
    Aug 2007
    Location
    Netherlands
    Posts
    10,283
    Mentioned
    51 Post(s)
    Tagged
    2 Thread(s)
    If they click yes I'll take them to the form, if no then I will redirect them to a different page.
    Question: why is this set up like this?

    Could this just be two anchors, disguised as buttons? If they click one, they go to url=thepagewiththeform.html
    if they click the other, they go to url=someotherpage

    Radio-button-ness is preserved if they get shifted somewhere else either way, because you can't click two links simultaneously anyway.

    Or is there really MORE to this form than you showed (are they filling in other things, then hitting a radio button and their old data is supposed to go with them??)?


Bookmarks

Posting Permissions

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