Click to See Complete Forum and Search --> : Check whether check box exists or not???
shanuragu
09-19-2003, 08:58 AM
Hi
In a form how can check for the existence of check box when a submit button is clicked?? if check boxes are present in the form do the validation else alert a message saying that no check boxes exists.
urgent please help
shara
Are you dynamically adding/deleting checkboxes?
If so then use a global variable to keep track of the number of checkboxes
And if you still can't figure it out, give us a little code (the form and the JS, but not the whole page).
[J]ona
shanuragu
09-19-2003, 10:53 PM
Whether I add check boxes dynamicaly or not I just want to check for the existance of a check box in a form.
That is fine, can any one explain me what the following function does???
for(var a=0;a<document.all.length;a++) {
eleName=document.all(a).name+"";
if(eleName.substring(0, cboxName.length)==cboxName && eleName.length==cboxName.length)
max += 1;
}
shara
You just want to check if any checkboxes exist in the form? If so, you can use something like this, though I'm not sure of it's usefullness:
<script type="text/javascript">
function checkForm() {
checkbox = 0;
obj = document.forms[0].elements;
for (i=0;i<obj.length; i++) {
if (obj[i].type == "checkbox") {
checkbox = 1;
}
}
if (checkbox == 1) {
alert ("Checkbox(s) were found");
}
}
</script>
shanuragu
09-20-2003, 12:53 AM
Thanks Pyro, it is working fine.
shara:D