Web Hosting Talk







View Full Version : How to summit the form with validating?


titus123
03-11-2008, 12:10 PM
While validating the form with java script,
I have a submitted the form every option of validating Refresh the particular form.
I put summit option for button tool.
Then I change and put button option for submitting the form. Not refresh the form but the form not submitted
Kindly suggest me how to summit the form rectifying above errors with validating?

Steve_Arm
03-11-2008, 12:48 PM
Post some code.
With javascript you do a submit(); ( form_name_here.submit(); )

Xeentech
03-11-2008, 01:01 PM
This is how I handle it


<form onsubmit="validateForm()">
<!-- Form stuffs here -->
<input type="submit" value="OK" />
</form>


<script type="text/javascript>
function validateForm ()
{
var form = this;

// validation code

if (formIsValid)
return true;

alert('Validation error');
return false;
}
</script>

Steve_Arm
03-11-2008, 02:07 PM
try this


<form name="form1" action="" method="post">
<!-- Form stuffs here -->
<input type="button" value="OK" onclick="validateForm();" />
</form>


<script type="text/javascript>
function validateForm ()
{
var form = this;

// validation code

if (formIsValid)
{
document.form1.submit();
}
else
{
alert('Validation error');
return false;
}
}
</script>

mcrilly
03-11-2008, 04:41 PM
Just a quick note, I hope you're doing validation server-side as well? :)