Validation

javascript validation for textboxes which names are dynamic.

Page 1 of 1

1 Replies - 962 Views - Last Post: 24 March 2010 - 06:14 AM

#1 lakshman_436   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 23-March 10

Validation

Posted 24 March 2010 - 02:18 AM

hai Friends document.getElementsById is not working.
Can you help me.

<html>
<head>
<script type="text/javascript">
function validate()
{
var nmsn = document.getElementsById("oitmn");
var nmsw = document.getElementsById("oitmw");
var nmsc = document.getElementsById("oitmc");
for (i=0;i<nmsn.length;i++)
{
if (nmsn[i].value!='')
{
if (nmsw[i].value=='')
{
alert("Weight Empty!");
nmsw[i].focus();
return false;
}
if (nmsc[i].value=='')
{
alert("Charge Empty!");
nmsc[i].focus();
return false;
}
}
}
return true;
}
</script>
</head>
<body>
<form name="form1" method="POST" action="validation.php" onsubmit="return validate();">
<?php
echo "<table border='0'>";
$j=1;
while($j <=3)
{
$oitmn="oitmn".$j;
$oitmw="oitmw".$j;
$oitmc="oitmc".$j;
echo "<tr align='center'>";
echo "<td >".$j."</td>";
echo "<td><input type='text' name='$oitmn' id='oitmn' value='$_POST[$oitmn]' maxlength='15' size='25'/></td>";
echo "<td><input type='text' name='$oitmw' id='oitmw' value='$_POST[$oitmw]' maxlength='15' size='25'/></td>";
echo "<td><input type='text' name='$oitmc' id='oitmc' value='$_POST[$oitmc]' maxlength='15' size='25'/></td>";
echo "</tr>";
$j=$j+1;
}
echo "<input type='hidden' name='itmc' value='$j' />";
?>
<tr><td align="right" colspan="4"><input type="submit" name="Submit" /></td></tr></table>
</form>
</body>
</html>


regards,
lakshman.

This post has been edited by lakshman_436: 24 March 2010 - 02:23 AM


Is This A Good Question/Topic? 0
  • +

Replies To: Validation

#2 PennyBoki   User is offline

  • D.I.C Lover
  • member icon

Reputation: 55
  • View blog
  • Posts: 2,345
  • Joined: 11-December 06

Re: Validation

Posted 24 March 2010 - 06:14 AM

Maybe you should try with
document.getElementById


Also, :code:
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1