Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dynamic Forms with database access

Status
Not open for further replies.

LenLindquist

IS-IT--Management
Oct 17, 2002
31
0
0
US
I would like to use a select-option drop-down box to select a library name from a data table and then, on the same form without yet submitting, dynamically change the next drop-down box to list the staff working at that particular library from another data table.

I figure this will at least require an onChange JavaScript function on the first select. But then how do I get that value and use it in the next drop-down with asp?

Thanks much,
Len
 
When you say that you don't want to submit, do you mean that you don't want to make a server call? If you want to do the whole thing without calling the server a second time, then you need to send all the data tp the HTML page at the outset. All libraries go into 1 javascript array and then all the employees at each library go into an array for that library.... Something like this....

<script>
bkfstArr = new Array (&quot;Ham and Eggs&quot;,&quot;Pancakes&quot;,&quot;Waffles&quot;,&quot;Cereal And Toast&quot;)
lnchArr = new Array (&quot;BLT&quot;,&quot;Peanut Butter and Jelly&quot;,&quot;Grilled Cheese&quot;,&quot;Soup and Salad&quot;)
dnnrArr = new Array (&quot;Pizza&quot;,&quot;Tacos&quot;,&quot;Hamburgers&quot;,&quot;Fried Chicken&quot;,&quot;Grilled Salmon&quot;,&quot;Lasagna&quot;)

function selectionMade(){
//see if the second Select has been created
allSelects = document.getElementsByTagName(&quot;select&quot;)
allSelects.length == 1 ? newSelect = false : newSelect = true;

//see if a selection has been made
if (allSelects[0].selectedIndex == 0){
if (newSelect){
allSelects[1].style.display = &quot;none&quot;
}
return false;
}
if (!newSelect){
// create the second select
nextSelect = allSelects[0].cloneNode(true)
nextSelect.id = &quot;secondarySelect&quot;
allSelects[0].parentNode.appendChild(nextSelect)
}
else{
// erase the second select
nextSelect = allSelects[1]
for (x=1; x<nextSelect.options.length; x++){
nextSelect.options[x] = null
}
nextSelect.style.display = &quot;block&quot;
}
// populate the second select
inputArr = eval(allSelects[0].options[allSelects[0].selectedIndex].value + &quot;Arr&quot;)
for (x=0; x<inputArr.length; x++){
if (nextSelect.options[x]){
nextSelect.options[x].text = inputArr[x]
nextSelect.options[x].value = inputArr[x]
}
else{
newOption = document.createElement(&quot;option&quot;)
nextSelect.appendChild(newOption)
newOption.text = inputArr[x]
newOption.value = inputArr[x]
}
}
}
</script>

<body>
<form name=&quot;myForm&quot;>
<select name=&quot;mainSelect&quot; onChange=&quot;selectionMade()&quot;>
<option value=&quot;&quot;>Choose Meal
<option value=&quot;bkfst&quot;>Breakfast
<option value=&quot;lnch&quot;>Lunch
<option value=&quot;dnnr&quot;>Dinner
</select><br>

Programming today is a race between software engineers striving to build better and bigger idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. - Rich Cook
 
Did something similar myself, i used a url and built up the params to then load into a select
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top