...

View Full Version : confirm alert and checkbox validation



vineet
06-22-2009, 04:50 AM
hi all

i have one form inside other form in which i have delete button and i want to apply validation on it.

This is form code


<form id="form1" name="form1" method="get" action="" onsubmit='return cbox();'>
<?
echo "<form name='del_sel' method='post'>";
echo "<td valign='top' colspan='9'><input name='submit' type='submit' value='Delete Selected' onClick=\"return confirm('Are you 100% totally certain that you want to DELETE this ?')\"/>";
echo "<input type='hidden' name='checkbox[]' value=".$row2['order_id']." />";
echo "</td>";
echo "</form>";
?>
</form>



this is validation function which checks whether one checkbox is selected or not.


function cbox()
{
var chks = document.getElementsByName('checkbox[]');
var hasChecked = false;
for (var i = 0; i < chks.length; i++)
{
if (chks[i].checked)
{
hasChecked = true;
break;
}
}
if (hasChecked == false)
{
alert("Please select at least one.");
return false;
}
return true;
}


now the problem is that cbox() function and confirm function both appears one after another. i want that if cbox() returns true means if any one of the chekbox is selected then only the confirm alert should appear otherwise it should not appear.


vineet

Philip M
06-22-2009, 07:34 AM
If the checkbox is hidden I don't see how the user can select it. If you change it to
<input type='checkbox' name='checkbox[]'
then it works fine.



So - did anyone dare tell George Stephenson, "It's not Rocket science"?



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum