Hi everybody!
I have a problem with javascript and checkboxes !
Here is a similir version of the page that I have:
=============
<html>
<head>
<script language="Javascript">
<!--
function isChecked( form, name )
{
var g = form.elements[ name ];
//alert(g.length);
for(var i = 0, n = g.length; i < n; ++i )
{
if( g[ i ].checked )
return true;
}
return false;
}
var clickedButton;
function validate( form )
{
if( !isChecked( form, "entries[]" ))
{
alert( "ERROR: No entry/entries selected !!!" );
return false;
}
// Check to see which buttons was clicked.
if (clickedButton.value == 'Delete')
{
return confirm("Are you sure you want to delete selected
entry/entries ?");
}
if (clickedButton.value == 'Edit')
{
return true;
}
return false;
}
//-->
</script>
</head>
<body>
<h3>Records</h3>
<form name='display' method='POST' onsubmit='return validate(this);'
action='dosomething.php' >
<table border=1>
<tr>
<td></td>
<th>Heading1</td>
<th>Heading2</td>
<th>Heading3</td>
</tr>
<tr>
<td><input type='checkbox' name='entries[]' value='entryID1'></td>
<td >Something</td>
<td >Something</td>
<td >Something</td>
</tr>
<tr>
<td><input type='checkbox' name='entries[]' value='entryID2'></td>
<td >Something</td>
<td >Something</td>
<td >Something</td>
</tr>
<tr>
<td><input type='checkbox' name='entries[]' value='entryID3'></td>
<td >Something</td>
<td >Something</td>
<td >Something</td>
</tr>
<tr>
<td colspan=4>
<input type='submit' name='delete' value='Delete'
onclick='clickedButton=this'>
<input type='submit' name='edit' value='Edit'
onclick='clickedButton=this'>
</td>
</tr>
</table>
</form>
</body>
</html>
=============
It works fine when there are more than one entry ( row) in the table
(like the current page). However, when there is only one entry on the
page and when I click on "Delete" or "Edit", I always get the message
"No Entry/entries selected" even though I already select that entry (
The form is supposed to be submitted ).
Any help would be appreciated !!
Thanks,
Jay