if i understand what you're looking to do (and i'm not sure that i
do...), the following should work.  might be a better (more efficient)
way to write it...but i'm tired :)

i took the liberty of giving your form fields unique names and ID
values...and removing the onclick event from your submit button
(moving the function call to the onsubmit event of the form itself).

oh yeah, and i went with XHTML (closing all tags, quoting all
attributes, etc) :)

<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

<script type="text/_javascript_">
function showElements(frm) {
var counter;
for (var i=1; i<5; i++) {
counter = 0;
if (frm.elements['name' + i].value.length)  counter++;
if (frm.elements['age' + i].value.length)   counter++;
if (frm.elements['marks' + i].value.length) counter++;
if ((counter > 0) && (counter < 3)) {
alert('Please Enter All Values for Row ' + i);
return false;
}
}
return true;
}
</script>
</head>

<body>

<form showElements(this);">
<table>
<tr>
<td><input type="text" name="name1" id="name_1" /></td>
<td><input type="text" name="age1" id="age_1" /></td>
<td><input type="text" name="marks1" id="mark_1" /></td>
</tr>
<tr>
<td><input type="text" name="name2" id="name_2" /></td>
<td><input type="text" name="age2" id="age_2" /></td>
<td><input type="text" name="marks2" id="mark_2" /></td>
</tr>
<tr>
<td><input type="text" name="name3" id="name_3" /></td>
<td><input type="text" name="age3" id="age_3" /></td>
<td><input type="text" name="marks3" id="mark_3" /></td>
</tr>
<tr>
<td><input type="text" name="name4" id="name_4" /></td>
<td><input type="text" name="age4" id="age_4" /></td>
<td><input type="text" name="marks4" id="mark_4" /></td>
</tr>
</table>
<input type="submit" value="Click" name="final" />
</form>

</body>
</html>

--
Charlie Griefer

================================================
Marta was watching the football game with me when she said,
"You know, most of these sports are based on the idea of one group
protecting its territory from invasion by another group."
"Yeah," I said, trying not to laugh. Girls are funny.
[Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings] [Donations and Support]

Reply via email to