View Single Post
Old Aug 7th, 2005, 8:57 AM   #2
Cerulean
Professional Programmer
 
Cerulean's Avatar
 
Join Date: Apr 2005
Location: London, England
Posts: 459
Rep Power: 4 Cerulean is on a distinguished road
Firstly you want to catch the event that is fired before the forum is submitted. To do that, in your submit button add an onsubmit handler that calls a function:
<form id="form1">
  <input type="checkbox" ...
  <input type="submit" onsubmit="return validateData()" />
</input>
In the validateData function we can just get a reference to the form element with an ID of 'form1', and then go through all of it's checkboxes, and see which ones are checked and then tell the user.
function validateData() {
    form = document.getElementById("form1");
    // Loop through all of the input elements in the form..
    for(var i = 0; i < form.elements.length; ++i) {
        // If the element is a checkbox, and it is checked
        if(i.getAttribute("type") == "checkbox" && i.checked) {
            // Then add this checkbox to a list or whatever.
        }
    }
    return confirm("Are you sure you want to ...")
}
Cerulean is offline   Reply With Quote