You're using two functions to do something that one can do by itself. You're also using HTML event attributes, which are poor practice. The below code separates layout and operation in accordance with current best-practices (or at least the strain I agree with - all of them do it but in different ways and to different extents).
Code:
<form id="form1" name="form1" method="get" action="">
<?php
echo "<form name='del_sel' method='post'>";
echo "<td valign='top' colspan='9'><input name='submit' type='submit' value='Delete Selected'/>";
echo "<input type='hidden' name='checkbox[]' value=".$row2['order_id']." />";
echo "</td>";
echo "</form>";
?>
</form>
Code:
window.onload = function(){
document.forms.namedItem('form1').registerEventListener('submit', cbox, false);
};
function cbox(event)
{
event = event || window.event;
var success = true;
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.");
success = false;
}
success = success && confirm('Are you 100% totally certain that you want to DELETE this ?'))
if(!success)
event.preventDefault();
return success;
}
HTMLElement.prototype.registerEventListener = function(type, listener, useCapture){
if(this.addEventListener)
this.addEventListener(type, listener, useCapture);
else if(this.attachEvent)
this.attachEvent('on' + type, listener);
else
this['on' + type] = listener;
};
Bookmarks