leetee4000
07-02-2009, 01:53 PM
All I want to do is determine whether the selected checkbox is on or off. At the moment, when the checkbox is ticked or unticked the javascript returns false. Any help much appreciated.
<form name="update_active" method="POST">
<input type="checkbox" name="active" onClick="updateActive(1, 'product')" />1
<input type="checkbox" name="active" onClick="updateActive(2, 'product')" />2
<input type="checkbox" name="active" onClick="updateActive(3, 'product')" />3
<input type="checkbox" name="active" onClick="updateActive(4, 'product')" />4
</form>
//is checkbox on or off?
function updateActive(id, type)
{
//is checkbox on or off?
for (var i=0; i < document.update_active.active.length; i++)
{
if (document.update_active.active[i].checked){
var active = 'y';
} else {
var active = 'n';
}
}
alert(active);
}
<form name="update_active" method="POST">
<input type="checkbox" name="active" onClick="updateActive(1, 'product')" />1
<input type="checkbox" name="active" onClick="updateActive(2, 'product')" />2
<input type="checkbox" name="active" onClick="updateActive(3, 'product')" />3
<input type="checkbox" name="active" onClick="updateActive(4, 'product')" />4
</form>
//is checkbox on or off?
function updateActive(id, type)
{
//is checkbox on or off?
for (var i=0; i < document.update_active.active.length; i++)
{
if (document.update_active.active[i].checked){
var active = 'y';
} else {
var active = 'n';
}
}
alert(active);
}