Question about SELECT element

D

datactrl

Hi, all

On a SELECT object, I try to set it's value with one of the value of
options, such as selectObj.value="whatever". Sometime it works while
sometimes it won't work at all , using IE6. When we want to set a value to
the SELECT object, have to know it's option index first. Then set
selectedIndex to that index. Is there a quick way to set a select value with
a known value?

Jack
 
M

Matt Kruse

datactrl said:
Is there a quick way to set a
select value with a known value?

There is no "quick" way. You need to cycle through all the options, find the
option (or options) that have a value matching yours, and mark them as
selected.

You can hide this all in a general function, though, which I find to be most
convenient.
Then, using functions from http://www.mattkruse.com/javascript/validations/
for example, you can just do:

setInputValue(document.forms[0].selectObj,"myValue");

and this will work regardless of input type.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,781
Messages
2,569,615
Members
45,294
Latest member
LandonPigo

Latest Threads

Top