Hi , here is the code......here i am getting some values from the database and displaying it
with an checkbox as given below,,,,i want to validate those checkboxes,,,,,whether the user is selected or not , as soon he clicks the submitt button......and here here the values are comming from different table based on user request, so as soon as those values displays with an checkbox i want to validate.....i have given same name for all checkbox as u can see........just help me out.......

<?php

	include('database.php');


 $stype=$_POST['category'];


if($stype=="service_category")
   { 
	 
	  $result = mysql_query("SELECT * FROM  service_category ");

	while($row = mysql_fetch_array($result))
	{

	?> <input type="Checkbox" name="contype[]"  value="A">
  <? 
		echo $row['servicec'];
	echo "<br />";
	}

   }
  
  else if($stype=="servicetype")
		 { 
	 
		$result = mysql_query("SELECT * FROM  service_type ");
		while($row = mysql_fetch_array($result))
				{
				?><input type="Checkbox" name="contype[]"  value="B"> <?echo $row['servicet'];
				echo "<br />";
				
				}
			}
		else
			{	
			$result = mysql_query("SELECT * FROM  services ");
			while($row = mysql_fetch_array($result))
			{
				?><input type="Checkbox" name="contype[]"  value="C"> <?echo $row['servicess'];
				echo "<br />";
				
				}
	  }
mysql_close();

?>
Use this script in your php page:
<script>
function comparision(){
		d=document.form1;
		var total="";
		if(!d.c.length){
			if(d.c.checked) {
				d.check_compare.value=d.check_compare.value+d.c.value+',';
				return true;
			} else {
				alert("Please select check Box");
				return false;
			}		
		}
		for(var i=0; i < d.c.length; i++){
			if(d.c[i].checked) {
				total +=d.c[i].value + "\n";
				d.check_compare.value=d.check_compare.value+d.c[i].value+',';
			}
		}
		if(d.check_compare.value=="") {
		 alert("Please select atleast one check Box");
		 return false;
		}
	}
</script>
And wirte this code to get what values selected on prevoius page..

<?
session_start();
include_once("../includes/functions.php");
if(isset($_POST['check_compare']))
{
$tempids=$_POST['check_compare'];	
echo $tempids;

$ser_qry="select * from products where find_in_set(p_id,'".$_POST['check_compare']."')";
$ser_res=mysql_query($ser_qry);
$ser_cnt=mysql_num_rows($ser_res);

}
?>


And use form tag and wirte the above code which have posted early..

<form name="form1" action="nextpage.php" method="post" onSubmit="return comparision()">
		<input type="hidden" name="check_compare">

Your code
</form>

If any queries ask me..

Hi, i got ur code, but in (d.c.length) what is c ......i have replaced the c with checkbox name
i,e contype.......its not working as soon as i clik the submit button it will go to next page...it does not say that i have not selected even single item...........if u want i will send the entire code.......pls reply

Exactly c is the check box name...
I tried it.it works..
Send me ur code...

hi......here is my code.....which is a big code ......

<? include("header.php") ?>	 
<html>
<head><title>auto alto</title></head>
<script>
function comparision(){
d=document.form2;
var total="";
if(!d.contype.length){
if(d.contype.checked) {
d.check_compare.value=d.check_compare.value+d.contype.value+',';
return true;
} else {
alert("Please select check Box");
return false;
}
}
for(var i=0; i < d.contype.length; i++){
if(d.contype[i].checked) {
total +=d.contype[i].value + "\n";
d.check_compare.value=d.check_compare.value+d.contype[i].value+',';
}
}
if(d.check_compare.value=="") {
alert("Please select atleast one check Box");
return false;
}
}
</script>
<body>

<table width="960" border="0" cellpadding="0" cellspacing="0" align="center">
 <tr>
 <td width="100%"><? include("top_banner.php") ?></td>			     
</tr>
 <tr>
 <td align="center" height="48" width="100%"><? include("horizental_menu.php") ?></td>
 </tr>

<table align="center" cellpadding="0" cellspacing="0" width="100%" border="0" class="whitesite" >
		<!-- header -->
<tr><td>		
<table cellpadding="0" cellspacing="0" width="100%" border="0">
<tr><td background="images/button_bot.gif" width="100%" height="5" colspan="3"></td></tr>
</table>
</td></tr>
	<!-- content -->
<tr><td width="100%">
<table cellpadding="0" cellspacing="0" width="100%" border="0">
<tr>

<td width="5">&nbsp;</td>
<td width="207" valign="top" class="" align="center">
<table cellpadding="0" cellspacing="0" width="207" border="0" align="center">
<tr><td height="5"></td></tr>
		
		
<tr><td align="center"  width="207">
<table cellpadding="1" cellspacing="1" width="195" align="center" border="0">
</table>
</td></tr>
		
<tr><td height="5"></td></tr>
<tr><td height="5"></td></tr>
<tr><td height="5"></td></tr>
</table>
</td>
<td width="5">&nbsp;</td>
	
<td valign="top">
<table cellpadding="0" cellspacing="0" width="100%" border="0">
<tr><td height="5"></td></tr>
<tr>
<td width="100%">
<table border="0" cellpadding="0" cellspacing="0" width="100%" align="center">
<tr>
<td><img src="images/box_left.gif" width="10" height="31" alt=""></td>
<td nowrap  background="images/box_topbg.gif" width="100%" height="31">
<table cellpadding="0" cellspacing="0" width="100%" border="0">
<tr>
			
	<td style="padding-left:5px;" class="headtitle">Service Provider </td>
</tr>
</table>
<td><img src="images/box_right.gif" width="10" height="31" alt=""></td>
</tr>
<tr>
	<td background="images/box_leftbg.gif" width="10"></td>
	<td bgcolor="#FFFFFF">
											<table cellpadding="0" cellspacing="0" width="100%">
												
																								
												<tr><td height="30">Register now to bid on <b>eGlazers</b> site. It's easy and <b>free</b>. Already registered? <span style="color:005D95"><strong>Sign in now</strong></span>.</td></tr>
												<tr><td align="right" colspan="3" style="color:red">[ <span class="error_text">*</span> ] <span class="mandi">indicates required fields</span></td></tr>
												<tr><td height="15"></td></tr>
												<form name='form2' method='post' action="contractor.php" onsubmit="return comparision(this);" > 
												<!-- <form name='form1' method='post' action="">-->
													<tr><td>
														<table border="0" cellpadding="1" cellspacing="5" align="center" width="100%" style="border:1px solid #EDEDED;background-color:#f6f6f6">
															
												<tr><td>				



<?php

	include('database.php');


 $stype=$_POST['category'];


if($stype=="service_category")
   { 
	 
	  $result = mysql_query("SELECT * FROM  service_category ");

	while($row = mysql_fetch_array($result))
	{

	?> <input type="Checkbox" name="contype"  value="A">
  <? 
		echo $row['servicec'];
	echo "<br />";
	}

   }
  
  else if($stype=="servicetype")
		 { 
	 
		$result = mysql_query("SELECT * FROM  service_type ");
		while($row = mysql_fetch_array($result))
				{
				?><input type="Checkbox" name="contype"  value="B"> <?echo $row['servicet'];
				echo "<br />";
				
				}
			}
		else
			{	
			$result = mysql_query("SELECT * FROM  services ");
			while($row = mysql_fetch_array($result))
			{
				?><input type="Checkbox" name="contype"  value="C"> <?echo $row['servicess'];
				echo "<br />";
				
				}
	  }
mysql_close();

?>


</td>
</tr>


	<tr ><td  colspan="2"></td><td><input  type='submit'  class="button1" name="reg" value="Register"></td></tr>
	</table>
   </td></tr>
	</form>
	</table>
	</td>
	<td background="images/box_rightbg.gif" width="10"></td>
  </tr>
  <tr>
	<td><img src="images/box_botleft.gif" width="10" height="10" alt=""></td>
	<td background="images/box_botbg.gif" width="100%" height="10" alt=""></td>
	<td><img src="images/box_botright.gif" width="10" height="10" alt=""></td>
</tr>
</table>
</td>
</tr>
</table>
</td>
<!-- right nav -->
<td width="5">&nbsp;</td>
<td width="207" class="borleftright" valign="top" align="center">
<table cellpadding="0" cellspacing="0" width="207" align="center"> 
<tr><td height="5"></td></tr>
<tr><td align="center"  width="207">
<table cellpadding="1" cellspacing="1" width="195" align="center" border="0">
<td></tr>
<tr><td height="5"></td></tr>
</table>
</td></tr>
</table>
</td>
<td width="5">&nbsp;</td>
</tr>
</table>
</td></tr>	
		<!-- footer -->
<tr>
		
		
		
		
		
		<!--    <td ><div align="center"><img src="images/vertical_line.jpg" alt="auto repair service list mechanic garage dark green line" width="940" height="8" /></div> -->
			<? include("footer.php") ?></td>
	    </tr>
      </table>
    </body>
</html>
commented: You have 23 posts already. Why don't you use [code] tags ? -1
<html>
<head><title>auto alto</title></head>
<script>
function comparision(){
d=document.form2;
var total="";
if(!d.contype.length){
if(d.contype.checked) {
d.check_compare.value=d.check_compare.value+d.contype.value+',';
return true;
} else {
alert("Please select check Box");
return false;
}
}
for(var i=0; i < d.contype.length; i++){
if(d.contype[i].checked) {
total +=d.contype[i].value + "\n";
d.check_compare.value=d.check_compare.value+d.contype[i].value+',';
}
}
if(d.check_compare.value=="") {
alert("Please select atleast one check Box");
return false;
}
}
</script>
<body>


<table align="center" cellpadding="0" cellspacing="0" width="100%" border="0" class="whitesite" >
<!-- header -->
<tr><td>
<table cellpadding="0" cellspacing="0" width="100%" border="0">
<tr><td background="images/button_bot.gif" width="100%" height="5" colspan="3"></td></tr>
</table>
</td></tr>
<!-- content -->
<tr><td width="100%">
<table cellpadding="0" cellspacing="0" width="100%" border="0">
<tr>

<td width="5">&nbsp;</td>
<td width="207" valign="top" class="" align="center">
<table cellpadding="0" cellspacing="0" width="207" border="0" align="center">
<tr><td height="5"></td></tr>


<tr><td align="center" width="207">
<table cellpadding="1" cellspacing="1" width="195" align="center" border="0">
</table>
</td></tr>

<tr><td height="5"></td></tr>
<tr><td height="5"></td></tr>
<tr><td height="5"></td></tr>
</table>
</td>
<td width="5">&nbsp;</td>

<td valign="top">
<table cellpadding="0" cellspacing="0" width="100%" border="0">
<tr><td height="5"></td></tr>
<tr>
<td width="100%">
<table border="0" cellpadding="0" cellspacing="0" width="100%" align="center">
<tr>
<td><img src="images/box_left.gif" width="10" height="31" alt=""></td>
<td nowrap background="images/box_topbg.gif" width="100%" height="31">
<table cellpadding="0" cellspacing="0" width="100%" border="0">
<tr>

<td style="padding-left:5px;" class="headtitle">Service Provider </td>
</tr>
</table>
<td><img src="images/box_right.gif" width="10" height="31" alt=""></td>
</tr>
<tr>
<td background="images/box_leftbg.gif" width="10"></td>
<td bgcolor="#FFFFFF">
<table cellpadding="0" cellspacing="0" width="100%">


<tr><td height="30">Register now to bid on <b>eGlazers</b> site. It's easy and <b>free</b>. Already registered? <span style="color:005D95"><strong>Sign in now</strong></span>.</td></tr>
<tr><td align="right" colspan="3" style="color:red">[ <span class="error_text">*</span> ] <span class="mandi">indicates required fields</span></td></tr>
<tr><td height="15"></td></tr>
<form name='form2' method='post' action="contractor.php" onsubmit="return comparision(this);" >
<input type="hidden" name="check_compare">
<!-- <form name='form1' method='post' action="">-->
<tr><td>
<table border="0" cellpadding="1" cellspacing="5" align="center" width="100%" style="border:1px solid #EDEDED;background-color:#f6f6f6">

<tr><td>



<?php

include('database.php');


$stype=$_POST['category'];


if($stype=="service_category")
{

$result = mysql_query("SELECT * FROM service_category ");

while($row = mysql_fetch_array($result))
{

?> <input type="Checkbox" name="contype" value="<? echo $row['servicec'];?>">
<br />
<? 
}

}

else if($stype=="servicetype")
{

$result = mysql_query("SELECT * FROM service_type ");
while($row = mysql_fetch_array($result))
{
?><input type="Checkbox" name="contype" value="<? echo $row['servicet'];?>">
<br />
<? 
}
}
else
{
$result = mysql_query("SELECT * FROM services ");
while($row = mysql_fetch_array($result))
{
?><input type="Checkbox" name="contype" value="<? echo $row['servicess'];?>">
<br />
<? 
}
}
mysql_close();

?>


</td>
</tr>


<tr ><td colspan="2"></td><td><input type='submit' class="button1" name="reg" value="Register"></td></tr>
</table>
</td></tr>
</form>
</table>
</td>
<td background="images/box_rightbg.gif" width="10"></td>
</tr>
<tr>
<td><img src="images/box_botleft.gif" width="10" height="10" alt=""></td>
<td background="images/box_botbg.gif" width="100%" height="10" alt=""></td>
<td><img src="images/box_botright.gif" width="10" height="10" alt=""></td>
</tr>
</table>
</td>
</tr>
</table>
</td>
<!-- right nav -->
<td width="5">&nbsp;</td>
<td width="207" class="borleftright" valign="top" align="center">
<table cellpadding="0" cellspacing="0" width="207" align="center">
<tr><td height="5"></td></tr>
<tr><td align="center" width="207">
<table cellpadding="1" cellspacing="1" width="195" align="center" border="0">
<td></tr>
<tr><td height="5"></td></tr>
</table>
</td></tr>
</table>
</td>
<td width="5">&nbsp;</td>
</tr>
</table>
</td></tr>
<!-- footer -->
<tr>





<!-- <td ><div align="center"><img src="images/vertical_line.jpg" alt="auto repair service list mechanic garage dark green line" width="940" height="8" /></div> -->
<? include("footer.php") ?></td>
</tr>
</table>

</body>
</html>

try this n ask me if any error occurs

Try praveen's code.
Its right...
And ask us,if any error arise...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.