Jump to content

Submit form on next page


smartzain

Recommended Posts

<td style="background-color:#eeeeee;width:1000px; text-align:left;" valign="top"><h1 class="heading">Registration Form</h1> <form name="myform" action="registration.html" method="get" id="myform" > <td align="right" colspan="2"><input type="submit" onclick="return validate();" name="submit" value="Submit" /> <input type="reset" value="Reset" /></td> Kindly tell me the right way to submit form on another page

Link to comment
Share on other sites

You can use JavaScript to validate the form, but you're going to need a server-side language to process the form. In other words, to submit form on another page and retrieve the info that's put into the form, you're going to need a server-side language to do that. Also, in case JavaScript is disabled on someones browser, I wouldn't rely only on JavaScript to validate forms. Server-side languages such as ASP, PHP, ColdFusion, etc should be used to validate your forms as well.

Link to comment
Share on other sites

Hi DON Eyesterday i was working on that form i was also make an asp file and wrote this file name in action="registration.asp" but when i was click on to the submit button so no validation occured and registration.asp file download automatically... kindly tell me the right way.

Link to comment
Share on other sites

dude! a normal validation script that would consist of

function validate(){var form_element = document.getElementById("myform")var valid = true;for(i=0;i<form_element.elements.length;i++){if(form_element.elements[i].type != "submit"){if(form_element.elements[i].value == form_element.elements[i].defaultValue || form_element.elements[i].value == ""){alert("Oops you forgot to "+form_element.elements[i].defaultValue);valid = false;}}}return valid;}

works fine dude! if using <form name="myform" action="registration.html" method="get" id="myform" onsubmit="return validate();" >

Link to comment
Share on other sites

That's because the

onsubmit="return validate();"

returned true in your case. If the validate() function returns true, the registration.asp file will be downloaded. If returns false, it will not go to registration.asp If you look at the validate() function dsonesuk wrote, you'll get an idea as to how the validating works. It returns either true or false.

Link to comment
Share on other sites

this is my form kindly check this.. <script type="text/javascript">function validateForm(){ if(document.getElementById("firstname").value == "") { document.getElementById("error_firstname").innerHTML = "First Name Required"; } if(document.getElementById("lastname").value == "") { document.getElementById("error_lastname").innerHTML = "Last Name Required"; } if(document.getElementById("country").value == "Select Your Country") { document.getElementById("error_country").innerHTML = "Select Country"; } if(document.getElementById("city").value == "") { document.getElementById("error_city").innerHTML = "City Requried"; } if(document.getElementById("email").value == "") { document.getElementById("error_email").innerHTML = "Email Address Required"; } if (document.getElementById("gender[0]").checked == false && document.getElementById("gender[1]").checked == false) { document.getElementById("error_gender").innerHTML = "Gender Required"; } return false;} <td style="background-color:#eeeeee;width:1000px;text-align:left;" valign="top"><h1 class="heading" >Registration Form</h1> <form name="myForm" action="registration.html" method="get" id="myForm" onsubmit="return validate();"> <table border="0" class="table"> <tr> <td>First name :*</td> <td><input type="text" name="firstname" id="firstname"/></td> </tr> <tr> <td></td> <td class="error"><div id="error_firstname"></div></td> </tr> <tr> <td>Last name :*</td> <td><input type="text" name="lastname" id="lastname" /></td> </tr> <tr> <td></td> <td class="error"><div id="error_lastname"></div></td> </tr> <tr> <td>Country :*</td> <td><select name="Country" id="country" /> <option>Select Your Country</option> <option value="United States">United States</option> <option value="United Kingdom">United Kingdom</option> </select></td> </tr> <tr> <td></td> <td class="error"><div id="error_country"></div></td> </tr> <tr> <td>City :*</td> <td><input type="text" name="city" id="city" /></td> </tr> <tr> <td></td> <td class="error"><div id="error_city"></div></td> </tr> <tr> <td>Email Address :*</td> <td><input type="text" email="emailaddress" id="email" value="" /></td> </tr> <tr> <td></td> <td class="error"><div id="error_email"></div></td> </tr> <tr> <td>Phone no :</td> <td><input type="text" name="phonenumber" value="" autocomplete="on"></td> </tr> <tr> <td valign="top">Gender :*</td> <td><input type="radio" name="gender" id="gender[0]" value="Male" /> Male <input type="radio" name="gender" id="gender[1]" value="Female"> Female</td> </tr> <tr> <td></td> <td class="error"><div id="error_gender"></div></td> </tr> <tr> <td valign="top">Like :</td> <td><input type="checkbox" name="Like" value="Yes" /> Yes <input type="checkbox" name="Like" value="No" /> No</td> </tr> <tr> <td valign="top">Addtional Request :</td> <td><textarea rows="8" cols="24"></textarea></td> </tr> <tr> <td align="right" colspan="2"><input type="submit" onclick="return validate();" value="Submit" /> <input type="reset" value="Reset" /></td> </tr> </table> </form>

Link to comment
Share on other sites

The form will always fail to submit, even though all the inputs are filled because you always 'return false;' at the very end. You should ONLY return a FALSE when any one of your if conditions is not met, else return true; and submit form.

function validateForm(){var valid=true;if(document.getElementById("firstname").value == ""){document.getElementById("error_firstname").innerHTML = "First Name Required";valid=false;}if(document.getElementById("lastname").value == ""){document.getElementById("error_lastname").innerHTML = "Last Name Required";valid=false;}if(document.getElementById("country").value == "Select Your Country"){document.getElementById("error_country").innerHTML = "Select Country";valid=false;}if(document.getElementById("city").value == ""){document.getElementById("error_city").innerHTML = "City Requried";valid=false;}if(document.getElementById("email").value == ""){document.getElementById("error_email").innerHTML = "Email Address Required";valid=false;}if (document.getElementById("gender[0]").checked == false && document.getElementById("gender[1]").checked == false){document.getElementById("error_gender").innerHTML = "Gender Required";valid=false;}return valid;}

which is it? validateForm() or validate() for onsubmit="return ..."

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...