Jump to content

Regarding Student Marks Validation


heshan

Recommended Posts

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>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.