|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
dynamic drop down box
hello
i have two drop down boxes: student id and student name on a web form. a database (ms access) has the student id and student name fields in a table. the drop down boxes should get their values from the table's fields respectively. i am ok with that (using asp) but my requirement is as follows: once i select a studentid from textbox1 then automatically the textbox2 should be selected with the corresponding student name. how can i do this using asp? or can javascript do the job too? thnx in advance, fmh002 |
|
#2
|
|||
|
|||
|
Two
ways you can do this.
First approach -------------------- Dynamically build your first combobox Server Side with the student id's so that you end up having: <select name="slcId" onchange="Load(this.options[selectedIndex].value)"> <option value="123">123</option> <option value="456">456</option> . . . . . . </select> As for the second combobox, don't build immediately. The idea behind this approach is that when a user select an item from your first combobox, it call a javascript function Load() notice the onchange attribute. Now the javascript function should be placed inside your <head>...</head> section of your page. What the function does is *refresh* the page(calling itself) passing the selected value by the user through/as a QueryString parameter. You then retrieve the parameter and re-execute another SQL Query to build the second combobox. Now the downfall of this approach is that a *refresh* of the page occurs and you might not want that. The second approach -------------------------- Is almost like the first one, but you build the two comboboxes Server side. The second combobox should be selected to an empty <option>...</option>. Also note that the second combobox should look something like: <option value="123">John Doe</option> that is the value attribute should be set to the student's ID Then inside the first combobox, have set the same way as in the first approach. Have call a javascript function like Load() for example and inside the function make the selected item inside the second combobox equal to the student Id that has been selected from the first combobox. There are plenty of example out there...search google.com for any if you'd like. Hope this helps! Sincerely Vlince |
|
#3
|
|||
|
|||
|
thnx for the prompt feedback. let me see how far i can implement it on my site.
peace, fmh002 |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > ASP Programming > dynamic drop down box |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|