?Selecting/Indexing Options elements by Name value 
Author Message
 ?Selecting/Indexing Options elements by Name value

Is there a way of selecting an Options list in a Select element by the text
value instead of a numeric index value without having to do a compare
against all option text values to get the relative numerical index value?

Background:  We have a Select element with a list of options.  When we do a
query against a db table we get a value that corresponds to one of these
selection options.  Using this value we want to set/scroll the corresponding
option into view.



Sun, 09 Feb 2003 03:00:00 GMT  
 ?Selecting/Indexing Options elements by Name value

Hi

Assuming a rs and the previous selection in prevValue

while(!rs.EOF)
        {
         sel = (rs("ID").value == prevValue) ? "selected" : "";
         Response.Write("<option value='" + rs("ID") + "' " + sel + ">" +
rs("theText") + "</option>");
         rs.MoveNext();
        }

--
Best Regards
 Vidar Petursson
==============================
  Microsoft Internet, Client, SDK MVP
==============================
 http://www.icysoft.com
 http://www.dna.is



==============================
 No matter where you go there you are
-

Quote:
> Is there a way of selecting an Options list in a Select element by the
text
> value instead of a numeric index value without having to do a compare
> against all option text values to get the relative numerical index value?

> Background:  We have a Select element with a list of options.  When we do
a
> query against a db table we get a value that corresponds to one of these
> selection options.  Using this value we want to set/scroll the
corresponding
> option into view.



Sun, 09 Feb 2003 03:00:00 GMT  
 ?Selecting/Indexing Options elements by Name value
Hi,
If you set the "id" of the option to the same as the value...and your values
are unique, you can use the select.options collection.  For example:
--------------------
<html>
<body>
<select id="selMe">
<option id="Val 1">Val 1</option>
<option id="Val 2">Val 2</option>
<option id="Val 3">Val 3</option>
<option id="Val 4">Val 4</option>
<option id="Val 5">Val 5</option>
<option id="Val 6">Val 6</option>
<option id="Val 7">Val 7</option>
</select>
<input type="button" value="Go to 'Val 6'"
onclick="selMe.options('Val 6').selected = true">
</body>
</html>
-----------------------

Quote:
> Is there a way of selecting an Options list in a Select element by the
text
> value instead of a numeric index value without having to do a compare
> against all option text values to get the relative numerical index value?

> Background:  We have a Select element with a list of options.  When we do
a
> query against a db table we get a value that corresponds to one of these
> selection options.  Using this value we want to set/scroll the
corresponding
> option into view.



Sun, 09 Feb 2003 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. ?Selecting/Indexing Options elements by Name value

2. ?Selecting/Indexing Options elements by Name value

3. How to dynamically select option in select element?

4. How to Show Selected Elements in Multiple Options

5. Selecting specific array index elements

6. changing select options based on previously selected options

7. Select element doesn't show first option?

8. Adding options to a select element

9. Background-color for SELECT / OPTION elements

10. how to add OPTION element in SELECT at runtime using Client side vbscripting

11. Adding OPTION Element to SELECT

12. CDO using select element options Help!!!!!!!!!

 

 
Powered by phpBB® Forum Software