...

View Full Version : Selecting multiple check boxes....



purush2purush
07-18-2007, 09:42 AM
I have developed an application in PHP.The user will find the list of experts and this code is generated based on the experts data in database..

It is working fine..

The users selects the expert according to his wish ( checks using check box provided before the expert and there is no restriction in selecting experts) .

Now he enters the question, he needs the reply and then he clicks on submit button.An email must be sent to the expert
I need the javascript to find whether the USER CHECKED the Check boxes or NOT.

Plz help ....

glenngv
07-18-2007, 08:58 PM
How are the checkboxes named? Do they have the same name or named differently with a pattern? Can you post a sample output for the checkboxes?

purush2purush
07-19-2007, 06:06 AM
This is my code...It is fetching data that is in mysql database tables,so i kept it in loop and it has only one name checkbox1....




mysql_connect("localhost","root") or die(mysql_error());
mysql_select_db("db_soft") or die(mysql_error());

$result = mysql_query("SELECT sfa_experts.display_name, sfa_skills.skill_name, sfa_skills.skill_desc
FROM sfa_experts, sfa_skills, sfa_expert_skills
WHERE sfa_experts.expert_uid = sfa_expert_skills.expert_uid
AND sfa_skills.skill_uid = sfa_expert_skills.skill_uid");

echo "<table border='1' align=center >
<tr>
<th>Expert Name</th>
<th>Profile</th>
<th>Area of Experience</th>
</tr>";
while($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td> <input type='checkbox' name='checkbox1'>" . $row['display_name'] . "</td>";
echo "<td>" . $row['skill_name'] . "</td>";
echo "<td>" . $row['skill_desc'] . "</td>";
echo "</tr>";
}
echo "</table>";
mysql_close();

glenngv
07-19-2007, 07:31 PM
The checkboxes should have a value (e.g. expert_uid) so that the server will know which experts are checked when the form is submitted.

function validate(f){
var chks = f.checkbox1;
var checked = false;
if (chks){ //checkbox(es) exist(s)
if (chks.length){ //multiple checkboxes
for (var i=0; i<chks.length; i++){
if (chks[i].checked){
checked = true;
break;
}
}
}
else { //single checkbox
checked = chks.checked;
}
if (!checked){
alert("Please checked at least one expert.");
return false;
}
}
return true;
}

<form name="frm" action="whatever.php" method="post" onsubmit="return validate(this);">

...checkboxes here

<input type="submit" value="Submit" />
</form>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum