heshan Posted October 12, 2012 Share Posted October 12, 2012 Hi all, I want to enter student marks to a form and i want to make sure the marks should be inserted to all the subjects, they are positive and should be within (0-100) range. Therefore i have created following validation.. Validations were successfully displayed..But the problem is whenever a validation say "insert values" displayes and then click on ok button suddenly the page redirects to the next page without allowing other fields to be filled..Can anyone tell me how can i avoid this problem??? <script type="text/javascript"> function checkForm(frm) { var id = frm.getElementsByTagName("input"); for (var i = 0; i < id.length-1; i++) { if (id[i].value == "") { alert("Please insert value"); id[i].focus(); return false; } if (id[i].value.match(/\D+/)) { alert("Please input positive integers only"); return false; } if(parseInt(id[i].value) > 100) { alert("Please input value less than 100"); id[i].focus(); return false; } } frm.submit(); return true; } </script> ---------------------------------------------------------------------------- <td><input type="submit" name="Submit" id="button" value="Save" onclick="checkForm(this.form);" /></td> Quote Link to comment Share on other sites More sharing options...
jazzman1 Posted October 13, 2012 Share Posted October 13, 2012 (edited) What result do you get? <script type="text/javascript"> function checkForm(frm) { alert (frm); return false; .......... </script> Edited October 13, 2012 by jazzman1 Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted October 13, 2012 Share Posted October 13, 2012 You are also validating this data server-side, right? 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.