Click to See Complete Forum and Search --> : checkboxes and dropdown lists


dag78
05-13-2008, 03:27 AM
Hi
I have a list of items that I have set up to generate in a checkbox system so that the end user can select the options in the checkbox list.
However i want each checkbox to have a dropdown list with 5 options in it.
the idea being that if a checkbox is ticked they select an option from the dropdown list and then it posts to a link table.

Anyone any idea how to do it?

Dave

cs3mw
05-13-2008, 05:08 AM
so if a check box is checked by a user then you want the user to have to click a choice from a select box? I would disable the select box and then once the user clicks the check box then the select box becomes enabled!

dag78
05-13-2008, 05:16 AM
any example code?

cs3mw
05-13-2008, 05:26 AM
Have a look at this

http://www.mredkj.com/tutorials/tutorial001.html

dag78
05-13-2008, 05:32 AM
ok thats great, so how would I then get my function to post my results?
Ie the users just created, the checkbox id and the dropdown id?
I have a link table that I want to get to store the 3 values

dag78
05-13-2008, 05:35 AM
and i need a dorpdown per checkbox

cs3mw
05-13-2008, 05:55 AM
could you explain a little more are the results that you want to post from a a database? Or is it an insert form where you want to insert the value that the user has chosen into a database?

Could you post the details of your select boxes and the database structure, and I may be able to help you more.

Mike

dag78
05-13-2008, 06:52 AM
the idea is that I have a table that has checkboxes and dropdowns in justified rows. the checkbox returns a value of breeds from the database and the dropdown returns a list of classes from the database.
I then want to seelct relevent breeds, select a class for that breed, then enter the breedid, classid and userid into a database link table

cs3mw
05-13-2008, 07:22 AM
Have a look at this example it will help you get started. Once you have something created post it if you are having further trouble.

http://www.dhtmlgoodies.com/scripts/ajax-chained-select/ajax-chained-select.html

dag78
05-13-2008, 07:48 AM
no example code there?

cs3mw
05-13-2008, 07:58 AM
There is example code on the above two links. Example code gives you an idea of how to create your code. Once you have an idea or drawn up some code then I will help you out if you get stuck! It is extremely difficult to find example code of something so specific so have a look at the two tutorials draw something up and then I will take a look if you are stuck!

dag78
05-13-2008, 09:00 AM
There are my 2 functions

function classs(){
$returnstr='<select name="class1">';
$query = 'select classID, class from judgeclass order by classID';
$result = @mysql_query($query);

while($classs=mysql_fetch_array($result)){
$returnstr= $returnstr.'<option value="'.$classs['classID'].'">'.$classs['class'].'</option>';
}

$returnstr= $returnstr.'</select>';
return $returnstr;
}

function breed(){
$returnstr='';
$query = "select breedid, breed from breed";
$result = @mysql_query($query);
$ii=0;
while($breeds=mysql_fetch_array($result)){
$returnstr= $returnstr.'<label><input type="checkbox" onclick=\"enable(this.checked)\" name="breedid_'.$ii.'" value="'.$breeds['breedid'].'" >'.$breeds['breed'].'</label><br />';
$ii++;
}
$returnstr= $returnstr.'<input type="hidden" name="breedcount" value="'.$ii.'"/>';

return $returnstr;
}


this is my script
<script language="JavaScript">
<!--
function disable(disableIt)
{
document.frm.class1.disabled = disableIt;
}
//-->
</script>

It posts to a form, but I only get one dropdown on screen that doesnt disable

dag78
05-13-2008, 09:01 AM
oh and i need to have a dropdwn per breed

cs3mw
05-13-2008, 09:29 AM
I would create the select boxes the following way

function classs(){
$returnstr='<select name="class1">';
$query = 'select classID, class from judgeclass order by classID';
$result = @mysql_query($query);
$nrows = mysql_num_rows($result);

for ($i=0;$i<$nrows;$i++) {
$row = mysql_fetch_array($result);
extract($row);
$returnstr= $returnstr.'<option value="'.$classs['classID'].'">'.$classs['class'].'</option>';
}

$returnstr= $returnstr.'</select>';
return $returnstr;
}

AS for the rest Im afraid your not explaining it enough for me to understand what you want. From what I can see I think you want to populate the first select box with all the classes in the judgeclass table and then once a user chooses a value from that select box the contents of the second one is populated. To do this you will need to post all code including php, html and javascript code. Read the example select boxes its an excellent example!!

dag78
05-13-2008, 09:34 AM
Apologies, I am wanting the following
firstly
a list of breeds with checkboxes.
secondly
a dorpdown list with the classes in to be selected once the checkbox is ticked

then finally to enter the userid, breedid and class id into a link table called judgeclasslink

Does that make sense?

cs3mw
05-13-2008, 09:48 AM
are the classes in the select boxes dependent on the breed selected so another words in your database set up can I breed have many classes?

dag78
05-13-2008, 09:55 AM
no the breed must have a class per user,
so user goes to register and they tick a breed, they must then select a class from the dropdown list, but only one class for their breed selected.
The user can select more than one breed and have a different class to another breed

dag78
05-13-2008, 09:57 AM
so in effect user a can select 5 breeds and attach classes a,b,b,c,d respectivly
user b can select 4 different breeds or some the same, and have classes a,a,d,d

cs3mw
05-13-2008, 10:05 AM
Yes but in the judgeclass table is there a foreign key which refers to the breedid from the breed table.

dag78
05-13-2008, 10:08 AM
no, ther eis a table that uas the user info in it
there is a judge class table which olds the classes and a breed table which holds the breeds,
i have created a link table called judgeclasslink, to hold the userID, breedid, and classid I will post this bit in a min

dag78
05-13-2008, 10:12 AM
function judge_register($name, $password)
{

// Store the information in the database
$query = "insert into judges (name, username, password, address1, address2, city, postcode, areaID, tel1, tel2, email, website, profile, distID, date) values ('$_POST[name]', '$_POST[username]', '$_POST[password]', '$_POST[address1]', '$_POST[address2]', '$_POST[city]', '$_POST[postcode]', '$_POST[area1]', '$_POST[tel1]', '$_POST[tel2]', '$_POST[email]', '$_POST[website]', '$_POST[profile]', '$_POST[dist1]', now())";
mysql_query ($query) or die ('Could not create judge.');


$query="select LAST_INSERT_ID() as id";

$result=mysql_query ($query);


if (mysql_num_rows($result) > 0)

{

$judgeID = mysql_fetch_array($result);

$judgeID=$judgeID['id'];


}
$count=count($breed);

//echo 'count='.$_POST['breedcount'].'--';

for($i=0;$i<$_POST['breedcount'];$i++){
if(isset($_POST['breedid_'.$i])){
$j=$i+1;
$BID=$_POST['breedid_'.$i];
//$CID=$_POST['class1'.$j];
$query= "insert into judgeclasslink(judgeID,breedid) values('$judgeID', '$BID')";
$a=mysql_query ($query) or die ('Could not add judge breed.');
}
}

cs3mw
05-13-2008, 10:19 AM
In your breed table ou need to have a foreign key which states that this class is related to this breed!!!!

dag78
05-13-2008, 10:22 AM
but they are not related
they are only related if a judge selects that option
so a three wat link table is needed

dag78
05-14-2008, 09:14 AM
ive now got it set up so it appears and dissapears, but i need it to be in a table of some sort. At the moment i can tick a box, but the dropdown list doesnt line up with the breed?

cs3mw
05-14-2008, 12:11 PM
post all your code including style sheets then and i'll have a look

dag78
05-19-2008, 07:59 AM
might be quicker to email them to you if your willing?

cs3mw
05-19-2008, 02:45 PM
no if you post it on here other users will be able to view it and may be able to help you.

dag78
05-26-2008, 05:35 AM
Here is may page i have put the parts in bold that need to line up

<?
include 'includes/db.inc.php';
include_once 'judgefunctions.php';
error_reporting(E_ALL ^ E_NOTICE); ?>
<!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>Show Dogs: Enter New Judge Profile, CV.</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<link href="showdogs.css" rel="stylesheet" type="text/css" />
<style type="text/css">
<!--
.style2 {font-weight: bold}
-->
</style>
<script>
function showMe (it, box) {
//alert(it);
var vis = (box.checked) ? "block" : "none";
document.getElementById(it).style.display ="inline";
}
</script>
</head>
<body bgcolor="#FBF6E7" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<!-- ImageReady Slices (showdogs.psd) -->
<div id="Table_01">
<table id="Table_01" width="793" height="849" border="0" cellpadding="0" cellspacing="0">
<tr>
<td height="114" colspan="2">
<img src="images/showdogs_01.gif" width="793" height="114" alt="" /></td>
</tr>
<tr>
<td height="24" colspan="2" axis="menutop"><div align="center">
<? include 'includes/generallinks.php'; ?></div> </td>
</tr>
<tr>
<td height="120" colspan="2">
<img src="images/showdogs_03.gif" width="793" height="120" alt="" /></td>
</tr>
<tr>
<td width="229" valign="top" bgcolor="#FBF6E7">
<? include 'includes/judgemenu.php'; ?></td>
<td width="564" height="544" valign="top" bgcolor="#FBF6E7"><strong><u>Enter new judge profile details</u><br /><br />
<?php if (isset($reg_error)) { ?>
There was an error: <?php echo $reg_error; ?> Please try again.
<?php } ?>
</strong>
<form action="judgeregister.php" method="post" enctype="multipart/form-data" class="style2">
<table width="553" border="0">
<tr>
<td valign="top">Judge Name</td>
<td valign="top"><input type="text" size="20" maxlength="20" name="name" <?php if (isset($_POST['name'])) { ?> value="<?php echo $_POST['name']; ?>"
<?php } ?>/></td>
</tr>
<tr>
<td valign="top">Username</td>
<td valign="top"><input type="text" size="20" maxlength="20" name="username" <?php if (isset($_POST['username'])) { ?> value="<?php echo $_POST['username']; ?>"
<?php } ?>/></td>
</tr>
<tr>
<td width="109" valign="top">Password</td>
<td width="434" valign="top"><input type="text" size="20" maxlength="20" name="password" /></td>
</tr>
<tr>
<td valign="top">Confirm password</td>
<td valign="top"><input type="text" size="20" maxlength="20" name="confirmpass" /></td>
</tr>
<tr>
<td valign="top">Address1</td>
<td valign="top"><input type="text" size="20" maxlength="20" name="address1" <?php if (isset($_POST['address1'])) { ?> value="<?php echo $_POST['address1']; ?>"
<?php } ?>/></td>
</tr>
<tr>
<td valign="top">Address2</td>
<td valign="top"><input type="text" size="20" maxlength="20" name="address2" <?php if (isset($_POST['address2'])) { ?> value="<?php echo $_POST['address2']; ?>"
<?php } ?>/></td>
</tr>
<tr>
<td valign="top">City</td>
<td valign="top"><input type="text" size="20" maxlength="20" name="city" <?php if (isset($_POST['city'])) { ?> value="<?php echo $_POST['city']; ?>"
<?php } ?>/></td>
</tr>
<tr>
<td valign="top">County</td>
<td valign="top"><? echo club_getAreaDropdownListjudge() ?></td>
</tr>
<tr>
<td valign="top">Post Code</td>
<td valign="top"><input type="text" size="20" maxlength="20" name="postcode" <?php if (isset($_POST['postcode'])) { ?> value="<?php echo $_POST['postcode']; ?>"
<?php } ?>/></td>
</tr>
<tr>
<td valign="top">Phone</td>
<td valign="top"><input type="text" size="20" maxlength="20" name="tel1" <?php if (isset($_POST['tel1'])) { ?> value="<?php echo $_POST['tel1']; ?>"
<?php } ?>/></td>
</tr>
<tr>
<td valign="top">Mobile</td>
<td valign="top"><input type="text" size="20" maxlength="20" name="tel2" <?php if (isset($_POST['tel2'])) { ?> value="<?php echo $_POST['tel2']; ?>"
<?php } ?>/></td>
</tr>
<tr>
<td valign="top">Email Address</td>
<td valign="top"><input type="text" size="20" maxlength="120" name="email" <?php if (isset($_POST['email'])) { ?> value="<?php echo $_POST['email']; ?>"
<?php } ?>/></td>
</tr>
<tr>
<td valign="top">Website Address</td>
<td valign="top"><input type="text" size="20" maxlength="50" name="website" <?php if (isset($_POST['website'])) { ?> value="<?php echo $_POST['website']; ?>"
<?php } ?>/></td>
</tr>
<tr>
<td valign="top"> Image</td>
<td valign="top"><input type="file" name="image" value=""/></td>
</tr>
<tr>
<td valign="top">Breeds</td>
<td valign="top"><table width="428" border="0">
<tr>
<td colspan="2" valign="top">Upon Selecting a breed, the class options will appear</td>
</tr>
<tr>
<td valign="top"><? echo breeds() ?> </td>
<td width="184" valign="top"><?php
$returnstr='';
$query = "select breedid, breed from breed order by breed";
$result = @mysql_query($query);
$ii=0;

while($breeds2=mysql_fetch_assoc($result)){
$k++;
?>
<div id="div<?=$k?>" style="display:none">
<? echo classes($k) ?></div><br /><? }?> </td>
</tr>
<tr>
<td width="223"> </td>
</tr>
</table></td>
</tr>
<tr>
<td valign="top">Select Traveling Distance</td>
<td valign="top"><? echo traveldist() ?></td>
</tr>
<tr>
<td valign="top">Profile</td>
<td valign="top"><textarea name="profile" rows="5" cols="45" <?php if (isset($_POST['profile'])) { ?> value="<?php echo $_POST['profile']; ?>"
<?php } ?> /></textarea></td>
</tr>
<tr>
<td colspan="2" valign="top"><input type="submit" name="submit" value="Submit" /></td>
</tr>
</table>
</form>
<strong><br />
</strong></td>
</tr>
<tr>
<td colspan="2">
<img src="images/showdogs_06.gif" width="793" height="26" alt="" /></td>
</tr>
<tr>
<td colspan="2" axis="bottommenu"><div align="center"><? include 'includes/bottommenu.php'; ?></div></td>
</tr>
</table>
</div>
<!-- End ImageReady Slices -->
<script src="http://www.google-analytics.com/urchin.js" type="text/javascript">
</script>
<script type="text/javascript">
_uacct = "UA-1590558-1";
urchinTracker();
</script>
</body>
</html>

dag78
06-05-2008, 08:07 AM
any joy on lining these boxes up at all?