PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
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
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);
}
zed420 wrote: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
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);
}