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
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