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;
 }
 }

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.

Member Avatar for diafol

Show your markup.

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;
        }
    }
}
Member Avatar for diafol

Again, show your markup.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.