zed420 Posted February 18, 2009 Share Posted February 18, 2009 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 Company 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 Company as a value it inserts the ID of it and same goes for the Site Name. I want the Company 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 <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); } Link to comment https://forums.phpfreaks.com/topic/145760-select-value-not-inserting/ Share on other sites More sharing options...
zed420 Posted February 18, 2009 Author Share Posted February 18, 2009 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 <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); } Link to comment https://forums.phpfreaks.com/topic/145760-select-value-not-inserting/#findComment-765496 Share on other sites More sharing options...
zed420 Posted February 19, 2009 Author Share Posted February 19, 2009 Anyone ???????? Link to comment https://forums.phpfreaks.com/topic/145760-select-value-not-inserting/#findComment-766399 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.