In article <5668e569.0405031849.6adaa70c@posting.google.com >,
artlover70@yahoo.com (Jay) wrote:
[color=blue]
> 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 ).[/color]
You were close to the problem with the commented out alert. When you
have only one row, you do not have an array of names, but a single
value. Perhaps there is some way of forcing a one element array of
names, but I do not know it. I added some special case code for the one
element array.
Minor changes:
- doctype
- title
- type="text/javascript" instead of the depreciated language attribute
- no need to hide javascript for Netscape release 1.
I tested this script in Netscape 7.1.
Robert
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<TITLE>One Row</TITLE>
<script type="text/javascript">
function isChecked( form, name )
{
var g = form.elements[ name ];
alert("name = " + name +
" g.length = " + g.length);
if (g.length == undefined)
{
alert("Only one row is present.");
if( g.checked )
{return true;}
}
else
{
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 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>