...

View Full Version : Validation script cant seem to work



shaun09
10-27-2006, 11:31 AM
I'm trying to validate some fields in my form but cant get it to work. I think its because of the submit button code. Could someone please help identify the problem.

<script language="JavaScript">
function validate_form ( )
{
if ( document.leaveform.dc1.value == "" )
{
alert ( "Please select start date" );
valid = false;
return valid;

}
}


<input name="b1" type="button" value="Submit Without Preview"
ONCLICK ="this.form.action ='fastsaveregistrationdetails.jsp';this.form.submit()">

probey20
10-27-2006, 08:24 PM
It's hard to see your problem since you left out the form tag, and you're also missing the ending script tag. But I think your problem was putting the action in the onclick event. Instead, define the action in the form tag like this:


<html>
<head>
<script language="JavaScript">
function validate_form ( )
{
if ( document.leaveform.dc1.value == "" )
{
alert ( "Please select start date" );
valid = false;
return valid;

}
}
</script>
</head>
<body>
<form method="post" action="fastsaveregistrationdetails.jsp">
<input name="b1" type="button" value="Submit Without Preview" ONCLICK ="this.form.submit();">
</form>
</body>
</html>

shaun09
11-13-2006, 02:13 AM
The problem is i cant change the following code as i'm using it for having multiple submit buttons on one form. I'm using jsp to draw the values. So what is present in the form tag doesnt make any difference. Please advice on how i can run the validation script based on this. Thank you..

<input name="b1" type="button" value="Submit Without Preview"
ONCLICK ="this.form.action ='fastsaveregistrationdetails.jsp';this.form.submit()">

probey20
11-13-2006, 05:11 PM
Unfortunately you can't run your validation code based on the Submit button code you posted. The reason is that your onClick event will submit the form EVERY TIME and will always skip the validate code because it is not getting called. You need to call your validation routine from the onClick event... I don't see anyway around it.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum