kcotter Posted April 12, 2011 Share Posted April 12, 2011 I'm very new to Java script and I've created a form with check boxes and a dropdown menu. I want to validate both on submit. I got it to work, but can't get them to work TOGETHER... I know I'm going about this wrong.. please help if possible... here's what I have: <script type="text/javascript"> function validate(form) { if(!document.form1.agree.checked){alert("Please check the terms and conditions"); return false; } return true; } </script> <form name="form1" method="post" action="sendorderform.php" onsubmit="return validate(this)"> AND <SCRIPT LANGUAGE="JavaScript"'> <!-- function validateForm(){ if(document.form1.emailto.selectedIndex==0) { alert("Please select an Item."); document.form1.emailto.focus(); return false; } return true; } //--> </SCRIPT> <form name="form1" method="post" action="sendorderform.php" onsubmit="return validateForm()"> Both of these, when put on the page alone, work great. But I don't know how to get them to work together. I need onsubmit to validate both things... Google isn't helping very much. Any help would be great!!! Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/233427-probably-simple-simple-simple/ Share on other sites More sharing options...
kcotter Posted April 12, 2011 Author Share Posted April 12, 2011 I figured it out... at least one way to do it... <script type="text/javascript"> function validate(form) { if(!document.form1.agree.checked){alert("Please check the terms and conditions"); return false; } if(document.form1.emailto.selectedIndex==0) { alert("Please select a store location"); document.form1.emailto.focus(); return false; } return true; } //--> </SCRIPT> <form name="form1" method="post" action="sendorderform.php" onsubmit="return validate(this)"> Thanks to anyone who might have been thinking about helping me. I'm all set now. Quote Link to comment https://forums.phpfreaks.com/topic/233427-probably-simple-simple-simple/#findComment-1200336 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.