piznac Posted September 26, 2007 Share Posted September 26, 2007 Not sure but not this script continues to send the form even though I have it to return false,.. very new to js,. any help would be nice: <script language="javascript" type="text/javascript"> function valid(){ if(document.or.cust_name.value == ""){ alert('Customer name must be filled out.'); return false; }else if(document.or.add1.value == ""){ alert('Address must be filled out.'); return false; }else if(document.or.state.value == ""){ alert('State must be filled out.'); return false; }else if(document.or.city.value == ""){ alert('City must be filled out.'); return false; }else if(document.or.zip.value == ""){ alert('Zipcode must be filled out.'); return false; }else if(document.or.p_name.value == ""){ alert('Project name must be filled out.'); return false; }else if(document.or.date.value == ""){ alert('Date needed must be filled out.'); return false; }else{ return true; } } </script> This is set on an "onsubmit" btw Quote Link to comment Share on other sites More sharing options...
php_tom Posted September 27, 2007 Share Posted September 27, 2007 Are the alerts working for you? If the alerts are working, but it still subimts the form when its invalid, we need to see the form submission code. I would try something like <script language="javascript" type="text/javascript"> function valid(){ if(document.or.cust_name.value == ""){ alert('Customer name must be filled out.'); return false; }else if(document.or.add1.value == ""){ alert('Address must be filled out.'); return false; }else if(document.or.state.value == ""){ alert('State must be filled out.'); return false; }else if(document.or.city.value == ""){ alert('City must be filled out.'); return false; }else if(document.or.zip.value == ""){ alert('Zipcode must be filled out.'); return false; }else if(document.or.p_name.value == ""){ alert('Project name must be filled out.'); return false; }else if(document.or.date.value == ""){ alert('Date needed must be filled out.'); return false; }else{ // The form is valid! Let's submit it... document.getElementById('myForm').submit(); } } </script> So this way, at the bottom of your form, you can have a button like this <input type='button' value='Submit' onclick='valid()' /> instead of <input type='submit' value='Submit' /> Hope this helps you... Quote Link to comment Share on other sites More sharing options...
piznac Posted September 27, 2007 Author Share Posted September 27, 2007 Yeah the alerts work,.. and I do have it setup like the 2nd example,.. I'll change it to a "button" and give that a go. Thanks,.. I'll report back,... Quote Link to comment Share on other sites More sharing options...
piznac Posted September 27, 2007 Author Share Posted September 27, 2007 Yep that seems to work,.. hey thanks man,.. Quote Link to comment 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.