Ahhhhhh... client side vbscript it is!!
Scrap the javascript idea -- If you can use vbscript, then let's do that.
First, you'll need to make sure that the dropdown box that you are going to dynamically populate has enough elements in it (initially defined) to hold the maximum number of elements. There's probably a way around this, but I don't know what it is, so...
Then, you have your recordset... the master table, I'm assuming will have multiple entries of countries and unique state entries. The code below will assume that that recordset exists and it will be called 'rs', and have two fields, 'country', and 'state'
Ok, so that's done. Now let's look at some code to populate the array:
Code:
<script language=vbscript>
dim stateArray(5, 50)
'make sure that the second number, again, will be big enough to hold the max # of states. The first number is the number of countries you will have
dim keyValue, i, whileCounter
for i = 1 to 5 'the number of countries to do (5, here)
keyValue = rs("country")
whileCounter = 1
while keyValue = rs("country")
stateArray(i, whileCounter) = rs("state")
rs.movenext
keyValue = rs("country")
whileCounter = whileCounter + 1
wend
next
</script>
So done -- array populated. Now, you will have to check the value of the country dropdown each time it is clicked in order to populate the state dropdown:
Code:
<select name="country" onClick="popStates">
<!-- insert all your options here -->
</select>
And then you need your 'states' element
Code:
<select name="states">
<!-- insert all your initial options here (blank ones, if you like)-->
</select>
Then, you have to make that popStates function to re-do the states element each time. It would look something like:
Code:
<script language=vbscript>
function popStates()
if document.formName.country.value = 1 then
for i = 1 to numOfElementsInStates
document.formName.states(i - 1).value = i
document.formName.states(i - 1).text = stateArray(1, i)
next
elseif document.formName.country.value = 2 then
for i = 1 to numOfElementsInStates
document.formName.states(i - 1).value = i
document.formName.states(i - 1).text = stateArray(2, i)
next
elseif document.formName.country.value = 3 then
for i = 1 to numOfElementsInStates
document.formName.states(i - 1).value = i
document.formName.states(i - 1).text = stateArray(3, i)
next
elseif document.formName.country.value = 4 then
for i = 1 to numOfElementsInStates
document.formName.states(i - 1).value = i
document.formName.states(i - 1).text = stateArray(4, i)
next
elseif document.formName.country.value = 5 then
for i = 1 to numOfElementsInStates
document.formName.states(i - 1).value = i
document.formName.states(i - 1).text = stateArray(5, i)
next
end if
end function
</script>
The values of the state entries will be the number of iterations you have taken in the loop, and the text will be whatever was in the recordset for that entry. You could probably afford to get a little more creative in how you give the values (like some value from the recordset), but that would involve (at least in this example) building a string when you populate the array, and then parsing it when you populate the element. Actually, your performance would probably suffer too much from that approach.
If there aren't the total number of entries in the array, it will just output a blank for both the value and the text of the option... no harm, no foul.
Let me qualify the above by saying it's not tested, and I just wrote it sitting here by reasoning it out... so more likely than not, it's probably got a syntax error or two in it, but I think you get the idea.
let me know how it works out

Paul Prewett