Link to home
Start Free TrialLog in
Avatar of Venkatagiri
Venkatagiri

asked on

Dynamically selecting an item as default in a drop-down menu

Is there a way to make different items in a drop-down menu as "selected" based on some previous information.  It is easy to set one item as "selected" while writing HTML.  Is there a way to do it dynamically using Java Script or VB Script?
Avatar of knightEknight
knightEknight
Flag of United States of America image

You can do it this way in general:

<SCRIPT language='javascript'>
  // the code below will select the 4th row in the list
  document.myform.myselect.selectedIndex = 3;
</script>

Let me know if you need more details.
... the above assumes this:

<FORM name='myform'>
 <SELECT name='myselect'>
  <OPTION></option>
   ...
 </select>
</form>
Avatar of Venkatagiri
Venkatagiri

ASKER

The solution you presented works.  But I have run into a problem for which, I wonder, if you have solution.  The selectedIndex in my page is a VBScript variable.  Is there a way to pass a VBScript variable to a JavaScript routine? Thanks for your help.
ASKER CERTIFIED SOLUTION
Avatar of knightEknight
knightEknight
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks for your help.  Mine was an ASP VBScript value.  
Your welcome, glad it worked!