Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Oct 2006
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Validation script cant seem to work

    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()">

  • #2
    New Coder
    Join Date
    Aug 2006
    Location
    Illinois
    Posts
    68
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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:

    Code:
    <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>
    Sarah

  • #3
    New to the CF scene
    Join Date
    Oct 2006
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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()">

  • #4
    New Coder
    Join Date
    Aug 2006
    Location
    Illinois
    Posts
    68
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.
    Sarah


  •  

    Posting Permissions

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