how to link to a different page

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • aperez74
    New Member
    • Mar 2013
    • 1

    how to link to a different page

    I'm using this coding to have someone enter text; if they have not entered anything when the click the button they get an alert box asking for some input.
    What I want is to send them to a New web page once they have actually entered something.

    I have tried <a href....but it appears on the page; I don't want that. I just want an automatic change to the new page after the button has been pressed and a valid input has been made.
    ---------------------------
    Code:
       <script type = "text/javascript">
          function validate(){
            // get inputs
            name = document.getElementById("txtName").value;
            
            //create an empty error message
            errors = "";
            
            //check name - It simply needs to exist
            if (name == ""){
              errors += "Please supply an answer…….. \n";
    	} 
    
            //end if               
              //check for errors
                if (errors == ""){
     
              //process the form
            } else {
             alert(errors);
            }    // end if  
          } // end function
        </script> </head> <body> <h1>Frame...</h1> <h3><center>Mary had a _________ whose fleece was white as _______</h3> <form action = "http://example.com/"> <fieldset> <label>Name</label> <input type = "text" 
    	size=75S%
                   value = ""
                   id = "txtName" /> <button type = "button"
                    onclick = "validate()">Check Your Answer </button>;
    
         </fieldset>
    Last edited by Dormilich; Mar 17 '13, 09:25 PM. Reason: Please use [CODE] [/CODE] tags when posting code.
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    change the button type to "submit" and make sure, that when the validation fails, the default action (the form submit) is cancelled.

    alternately, call the form’s submit() method in JS.

    Comment

    Working...