By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,984 Members | 2,615 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,984 IT Pros & Developers. It's quick & easy.

I want to fill budget code field when the department is selected in the combo box

P: 4
I have table departments with three fields DeptID, DepartmentName and budgetcode. Departments value are populated in the dropdown menu. i need to fill the text box of budgetcode when department is selected.

here is code for departmentlist is populated

Expand|Select|Wrap|Line Numbers
  1. <select name="Department" id="Department" onChange="showText();">
  2.                 <option value="notselected" selected>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</option>
  3.                 <%
  4.     set rs1=server.createobject("adodb.recordset")
  5.     DepartmentSQL="Select DeptID,DepartmentName,bcode from departments order by Departmentname"
  6.  
  7.     rs1.open DepartmentSQL,cn,3
  8.  
  9.     while not rs1.eof
  10.                  DepartmentID=rs1("DeptID")
  11.                  DepartmentName=rs1("DepartmentName")
  12.                  bcode=rs1("bcode")
  13.             %>
  14.                 <option value="<%=DepartmentName%>"><%=DepartmentName%></option>
  15.                 <%rs1.movenext
  16.       wend
  17.  
  18.      %>
  19.               </select>
Jun 24 '13 #1
Share this Question
Share on Google+
6 Replies


Dormilich
Expert Mod 5K+
P: 8,639
that us usually done through AJAX. you fetch the data by using the selected value and insert the returned data in your output container.
Jun 24 '13 #2

P: 4
Can you please write it here to help me out
Jun 24 '13 #3

Dormilich
Expert Mod 5K+
P: 8,639
I can help improve your code.
Jun 24 '13 #4

P: 4
Please it would be great!
Jun 24 '13 #5

Dormilich
Expert Mod 5K+
P: 8,639
show us what you tried.
Jun 24 '13 #6

P: 4
The function i am using to fill the value but it is not working.
Expand|Select|Wrap|Line Numbers
  1. function showText()
  2.       {
  3.  
  4.         //This functions is used show selected value of listbox into textbox.
  5.          var objselect;
  6.          var txtval;
  7.         objselect=document.forms['form1'].Departments;
  8.  
  9.        //Get the selected value from listbox
  10.         txtval=objselect.options[objselect.selectedIndex].value;
  11.  
  12.        //Display it in textbox 
  13.         document.getElementById('Budget_Code').value = txtval; 
  14.       }
The database is in access
Departments table there are three field. DeptID, DepartmentName and bcode.
Here is the code for department list
Expand|Select|Wrap|Line Numbers
  1. <select name="Department" id="Department" onChange="showText();">
  2.                 <option value="notselected" selected>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</option>
  3.                 <%
  4.     set rs1=server.createobject("adodb.recordset")
  5.     DepartmentSQL="Select DeptID,DepartmentName,bcode from departments order by Departmentname"
  6.  
  7.     rs1.open DepartmentSQL,cn,3
  8.  
  9.     while not rs1.eof
  10.                  DepartmentID=rs1("DeptID")
  11.                  DepartmentName=rs1("DepartmentName")
  12.                  bcode=rs1("bcode")
  13.             %>
  14.                 <option value="<%=DepartmentName%>"><%=DepartmentName%></option>
  15.                 <%rs1.movenext
  16.       wend
  17.  
  18.      %>
  19.               </select>
Jun 24 '13 #7

Post your reply

Sign in to post your reply or Sign up for a free account.