Forum Moderators: coopster
I'm sorry if this is little confusing. Thanks in advance
Zed
<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>
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);
}
echo "addOption(document.emp_rec.cl_name, '$nt1[client_id]','$nt1[client_name]');";
... and then look how you are assigning the parameters in the JavaScript function, value is the second argument, which is the id:
function addOption(selectbox, value, text )
{
var optn = document.createElement("OPTION");
optn.text = text;
optn.value = value;
selectbox.options.add(optn);
}
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.
Whatever is in the value of an option element is what will be submitted in the $_POST index for that element name. In this case, it is going to be the ID.
It looks to me like you have your 2nd and 3rd arguments reversed in your JavaScript function.