TBor
05-28-2003, 10:25 AM
Hi all. Hopefully this is an easy one:
I'm trying to have a VBScript subroutine change the selected value of a SELECT box. However, the SELECT box is dynamically filled from database values (ASP), so selecting the Option statement that I want by specifying an integer for selectedIndex is pretty much out of the question.
I would like to change the Option selected based on the Value of that Option, if possible. I know the Value is always going to be unique within the SELECT box (it's a user ID).
Here's an example of what I am looking for (of course, the subroutine as written doesn't work):
sub ChangeOption(optionValue)
document.form.name.selected.value = optionValue
end sub
...
<form>
<select id="name" name="name">
<option value="user1" selected>Dave</option>
<option value="user2">Bob</option>
<option value="user3">Joe</option>
<option value="user4">Steve</option>
</select>
<input type="button" onClick="ChangeOption 'user3'">
Seeing as the "real" SELECT list I'm using is ASP generated, and users change sometimes, I don't think I can use selectedIndex. For instance, as shown above, Joe would be selectedIndex=3 (or 2, I can't remember), but if Bob were to quit and be removed from the DB, Joe is still "user3", but the selectedIndex changes for Joe the next time the SELECT box options are generated.
Hopefully someone out here will let me know what to do, or if it can be done at all.
Thanks in advance,
TBor
I'm trying to have a VBScript subroutine change the selected value of a SELECT box. However, the SELECT box is dynamically filled from database values (ASP), so selecting the Option statement that I want by specifying an integer for selectedIndex is pretty much out of the question.
I would like to change the Option selected based on the Value of that Option, if possible. I know the Value is always going to be unique within the SELECT box (it's a user ID).
Here's an example of what I am looking for (of course, the subroutine as written doesn't work):
sub ChangeOption(optionValue)
document.form.name.selected.value = optionValue
end sub
...
<form>
<select id="name" name="name">
<option value="user1" selected>Dave</option>
<option value="user2">Bob</option>
<option value="user3">Joe</option>
<option value="user4">Steve</option>
</select>
<input type="button" onClick="ChangeOption 'user3'">
Seeing as the "real" SELECT list I'm using is ASP generated, and users change sometimes, I don't think I can use selectedIndex. For instance, as shown above, Joe would be selectedIndex=3 (or 2, I can't remember), but if Bob were to quit and be removed from the DB, Joe is still "user3", but the selectedIndex changes for Joe the next time the SELECT box options are generated.
Hopefully someone out here will let me know what to do, or if it can be done at all.
Thanks in advance,
TBor