0
Hi good evening,

    In a page I show a list of students with checkboxes dynamically and one message box.

When the user submit if no checkboxes (atleast one check box) selected, I want to show one alert meassage like "Please select atleast one student";
 I did in javascript like this , but it is not working for me. What and how to do this next?
 I validate this checkboxes while on submit the form.

 function showlist()
 {
 var a = document.getElementById('student').value;
 if(a.length < 1)
 {
 alert("Please Select Atleast one student");
 document.getElementById('student').focus();
 return false;
 }
 }
3
Contributors
4
Replies
19
Views
2 Years
Discussion Span
Last Post by diafol
0

If the element you are binding is a INPUT tag with type of checkbox, then you need to use a.checked instead of a.value. I don't know how you compose your HTML so can't say more.

0
function validate()
{
var count = 0;
var a = document.getElementById('stu').checked;
for(var i = 0; i < a.length; ++i)
    {
        if(a[i] == 0)
        {
            alert("Select atleast one student");
            return false;
        }
    }
}
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.