By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,456 Members | 1,742 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,456 IT Pros & Developers. It's quick & easy.

Multiple check box validation

P: 45
hi,
Expand|Select|Wrap|Line Numbers
  1. var len=document.form.check.length
  2. flag=false;
  3. for(i=0;i<len;i++)
  4. {
  5. if(document.form.check[i].checked==true)
  6. {
  7. flag=true;
  8. break;
  9. }
  10. }
  11. if(flag==false)
  12. {
  13. alert(select atlest one)
  14. }
  15.  
  16.  
my error is object is required
Feb 25 '08 #1
Share this Question
Share on Google+
6 Replies


P: 45
hi,my error is object is required.please any one help for a problem.....
Expand|Select|Wrap|Line Numbers
  1. var len=document.form.check.length
  2. flag=false;
  3. for(i=0;i<len;i++)
  4. {
  5. if(document.form.check[i].checked==true)
  6. {
  7. flag=true;
  8. break;
  9. }
  10. }
  11. if(flag==false)
  12. {
  13. alert(select atlest one)
  14. }
  15.  
  16.  
Feb 25 '08 #2

100+
P: 141
Hi ,

once check whether "form" is the id of the form and check is the id of the checkbox because i am not getting error and this code is fine


Expand|Select|Wrap|Line Numbers
  1. var len=document.form.check.length
  2. flag=false;
  3. for(i=0;i<len;i++)
  4. {
  5. if(document.form.check[i].checked==true)
  6. {
  7. flag=true;
  8. break;
  9. }
  10. }
  11. if(flag==false)
  12. {
  13. alert(select atlest one)
  14. }
  15.  
  16.  
Feb 25 '08 #3

acoder
Expert Mod 15k+
P: 16,027
Expand|Select|Wrap|Line Numbers
  1. alert(select atlest one)
alert('select at least one') - it should be a string.
Feb 25 '08 #4

P: 45
i have mutiple check box value error object required.......
Expand|Select|Wrap|Line Numbers
  1. aa
  2. <script type="text/javascript">
  3. function fnallocate()
  4. {
  5. var len=document.form.selcie.length
  6. flag=false;
  7. for(i=0;i<len;i++)
  8. {
  9. if(document.form.selcie[i].checked==true)
  10. {
  11. flag=true;
  12. break;
  13. }
  14. }
  15. if(flag==false)
  16. {
  17. alert("select atlest one");
  18. }
  19. </script>
  20. <body>
  21. <form action="checkbox.php" name="form" method="post">
  22. <?
  23.  $res=mysql_query("select * from cie where des='Resource Pipeline Associate' order by name");
  24. $j=0;
  25.         $norow=mysql_num_rows($res);
  26.         $flag=false;
  27.     while($td=mysql_fetch_array($res))
  28.     {
  29.                 for($i=0;$i<count($can);$i++)
  30.  
  31.             {    
  32.                     if("$td[1]"=="$can[$i]")
  33.                     {
  34.                         $flag=true;
  35.                         $i=count($can);
  36.                     }
  37.                     else
  38.                     {
  39.                     $flag=false;
  40.                     }
  41.             }
  42.                 if($flag==true)
  43.                 {
  44. //print"        <tr><td><input type=\"checkbox\" name=\"selcie\"  value=\"$td[1]\" checked>$td[1]</td></tr>";
  45.                 }
  46.                 else
  47.                 {
  48. print"        <tr><td><input type=\"checkbox\" name=\"selcie\" value=\"$td[1]\" >$td[1]</td></tr>";                
  49.                 }
  50.                 $j++;
  51.     }    
  52. ?>         
  53.   <input type="submit" name="Submit" value="Submit" onclick="fnallocate()">
  54. </form>
  55. <?
  56.  
  57.  
  58. if(isset($_POST['Submit']))
  59. {
  60.     for ($i=0; $i<count($_POST['selcie']);$i++) {
  61.        echo "<br />value $i = ".$_POST['selcie'][$i];
  62.     }
  63. }
  64. ?>
  65. </body
  66.  
Feb 26 '08 #5

hsriat
Expert 100+
P: 1,654
[php]
<script type="text/javascript">
function fnallocate(len) {
for(i=0;i<len;i++) {
if(document.getelementById('selcie_'+i).checked==t rue)
return true;
}
alert("select atlest one");
return false;
}
</script>
<body>
<form action="checkbox.php" name="form" method="post">
<?
$res=mysql_query("select * from cie where des='Resource Pipeline Associate' order by name");
$j=0;
$norow=mysql_num_rows($res);
$flag=false;
while($td=mysql_fetch_array($res))
{
for($i=0;$i<count($can);$i++)
{
if($td[1]==$can[$i])
{
$flag=true;
$i=count($can);
}
else
{
$flag=false;
}
}
if($flag==true)
{
echo "<tr><td><input type=\"checkbox\" id=\"selice_".$j."\" name=\"selcie[]\" value=\"$td[1]\" checked>$td[1]</td></tr>";
}
else
{
echo "<tr><td><input type=\"checkbox\" id=\"selice_".$j."\" name=\"selcie[]\" value=\"$td[1]\" >$td[1]</td></tr>";
}
$j++;
}
?>
<input type="submit" name="Submit" value="Submit" onclick="return fnallocate(".($j-1).")">
</form>
<?
if(isset($_POST['Submit']))
{
for ($i=0; $i<count($_POST['selcie']);$i++)
{
echo "<br />value $i = ".$_POST['selcie'][$i];
}
}
?>
</body>
[/php]

Try it this time...
Feb 26 '08 #6

acoder
Expert Mod 15k+
P: 16,027
i have mutiple check box value error object required...
Threads merged. Please do not double post.

Moderator
Feb 26 '08 #7

Post your reply

Sign in to post your reply or Sign up for a free account.