I've tried searchign for the answer to this already but I just can't figure it out I hope someone can help.
I have a set of four checkboxes and I want one of them to be selected before the form is submitted. Now this sounds simple I know.. but I can't get it to work. Here's the code for the form:
And the code on the button:
I've tried all sorts of things and this is where the code currently stands at.. I'm am sureit is something simple..
Basically I need to check if the checkbox array, bookid[] is checked or not..
Many thanks to anyone who can help..
Nematoth
I have a set of four checkboxes and I want one of them to be selected before the form is submitted. Now this sounds simple I know.. but I can't get it to work. Here's the code for the form:
Code:
<form name="addbook" method="POST" action="<?=$sFileName?>">
<input type="checkbox" name="bookid[]" value="<?=$flda_bookid?>" class="blacktext01">
<input type="hidden" name="FormAction" value="addphone">
<input type="hidden" name="FormName" value="addbook">
<input type="hidden" name="forwardURL" value="recip_but.php">
<a href="#" target="_self" onclick="checkForm();"><img src="images/but_add01.gif" width="85" height="39" border="0"></a>
</form>
And the code on the button:
Code:
function checkForm()
{
var noChecked =0;
for(var i = 0; i < document.addbook.elements.length; i++)
{
if(document.addbook.elements.checked)
{
noChecked++;
}
}
if (noChecked !=1)
{
alert("Please select ONE name then click Add. Number of checkboxes checked:"+noChecked);
//alert("Please select ONE name then click Add/n/n"+document.addbook.elements.length);
return false;
}
else
{
alert("Submitting form");
document.addbook.submit();
}
}
</script>
I've tried all sorts of things and this is where the code currently stands at.. I'm am sureit is something simple..
Basically I need to check if the checkbox array, bookid[] is checked or not..
Many thanks to anyone who can help..
Nematoth