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 derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Client side Selection box changing

Status
Not open for further replies.

hdougl1

Programmer
Dec 6, 2000
54
US
How do I change the value of a selection box off a client side click event?
Here's the condensed view of the selection wraped in the form.

Response.Write &quot;<form name=modify action=track2k.asp method=post>&quot;
Response.Write &quot;<Select name=WorkChoice >&quot;
Response.Write &quot;<Option value='NA'>NA</Option>&quot;
Response.Write &quot;<Option value='Modify'>Modify</Option>&quot;
Response.Write &quot;</Select>&quot;
Response.Write &quot;<input type=button value='Select All' name=selector onclick=changeall()>&quot;
Response.Write &quot;</form>&quot;

Here's my attemp at changing the selection from the buttons click event client side.

<SCRIPT LANGUAGE=&quot;VBScript&quot;>
<!--
Sub changeall()
document.modify.WorkChoice.selected.value = &quot;Modify&quot;
End Sub
-->
</SCRIPT>

Thanks for looking at this.
Henry
 
here is a bit of VBScript.
'oFld is the name of your object
'sValue is the string you want to find


sub SetOptionIndex(oFld, sValue)
dim bFound

bFound = false
for x = 0 to oFld.length - 1
if oFld.options(x).value = sValue or oFld.options(x).text = sValue then
oFld.selectedindex = x
bFound = true
exit for
end if
next
if not bFound then oFld.selectedindex = -1

end sub
 
Here you go...

Code:
<BODY BGCOLOR=&quot;#FFFFFF&quot;>
<form name=modify action=track2k.asp method=post>
<Select size=8 multiple name=WorkChoice >
<Option value='NA'>NA</Option>
<Option value='Modify'>Modify</Option>
</Select>
<input type=button value='Select All' name=selector onclick=changeall()>
</form>

Here's my attemp at changing the selection from the buttons click event client side.

<SCRIPT LANGUAGE=&quot;VBScript&quot;>
<!--
Sub changeall()
	for each jonax in document.modify.workchoice
	jonax.selected = true
	next
End Sub
-->
</SCRIPT>
</BODY>
</HTML>
This is not a bug - it's an undocumented feature...
;-)
 
Awesome that worked THANKS A LOT!
fyi
I modified your instructions to stay with in my style of codeing. ex.

Sub changeall()
for i = 0 to document.modify.WorkChoice.length -1
document.modify.WorkChoice(i).selectedindex = 1
next
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top