Select value not inserting
Posted: Wed Feb 18, 2009 10:16 am
Hi All
I have a small problem with my code I hope someone can help me, the code below works fine apart from one thing that I can NOT seem to figure out. Two dropdown boxes populate from to another, onload it populates the Client Name and when you select one of them it populates the other(site_name) dropdown box with their site names as well as Client ID. When you select a Site Name it also populates the Site ID. The problem is in the database instead of inserting the Name of Client as a value it inserts the ID of it and same goes for the Site Name. I want the Client Name as value in cl_name box and Site Name as value in site_name box.
I'm sorry if this is little confusing. Thanks in advance
Zed
I have a small problem with my code I hope someone can help me, the code below works fine apart from one thing that I can NOT seem to figure out. Two dropdown boxes populate from to another, onload it populates the Client Name and when you select one of them it populates the other(site_name) dropdown box with their site names as well as Client ID. When you select a Site Name it also populates the Site ID. The problem is in the database instead of inserting the Name of Client as a value it inserts the ID of it and same goes for the Site Name. I want the Client Name as value in cl_name box and Site Name as value in site_name box.
I'm sorry if this is little confusing. Thanks in advance
Zed
Code: Select all
<td>Client ID : </td>
<td><input type="text" id="cl_id" name="cl_id" size="5" /></td></tr>
<td>Company Name : </td>
<td>
<SELECT NAME="cl_name" onChange="SelectSite();document.getElementById ('cl_id').value=this.value;" >
<Option value="">Company Name</option>
</select></td></tr>
<td>Site Name</td>
<td>
<SELECT NAME="site_name" id="site_name" onchange="document.getElementById('site_id').value=this.value;" >
<Option value="">Site(s) Name</option>
<?=$optionsid?>
</select>
</td></tr>
<tr><td>Client Site ID : </td>
<td><input type="text" name="site_id" id="site_id" size="5" /></td></tr>
Code: Select all
echo "
function fillCategory(){
// this function is used to fill the category list on load
";
$q1=mysql_query("select * from client");
echo mysql_error();
while($nt1=mysql_fetch_array($q1)){
echo "addOption(document.emp_rec.cl_name, '$nt1[client_id]','$nt1[client_name]');";
}// end of while
?>
} // end of JS function
function SelectSite(){
removeAllOptions(document.emp_rec.site_name);
addOption(document.emp_rec.site_name, "", "Site Name", "");
<?
$q2=mysql_query("select distinct(site_id) from client_site");
while($nt2=mysql_fetch_array($q2)){
echo "if(document.emp_rec.cl_name.value == '$nt2[site_id]'){";
$q3=mysql_query("select * from client_site where site_id='$nt2[site_id]'");
while($nt3=mysql_fetch_array($q3)){
echo "addOption(document.emp_rec.site_name,'$nt3[site_id]','$nt3[site_name]');";
} // end of while loop
echo "}"; // end of JS if condition
}
?>
}
function removeAllOptions(selectbox)
{
var i;
for(i=selectbox.options.length-1;i>=0;i--)
{
//selectbox.options.remove(i);
selectbox.remove(i);
}
}
function addOption(selectbox, value, text )
{
var optn = document.createElement("OPTION");
optn.text = text;
optn.value = value;
selectbox.options.add(optn);
}