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?
VenkatagiriAsked:
Who is Participating?
 
knightEknightConnect With a Mentor Commented:
Do you mean a server (ASP) VBScript variable or a client (Browser) VBScript variable?

If server:

  document.myform.myselect.selectedIndex = <%=MyVBValue%>;

If browser (IE only)

<SCRIPT language='vbscript'>
// the code below will select the 4th row in the list
  document.myform.myselect.selectedIndex = MyVBValue
</script>
0
 
knightEknightCommented:
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.
0
 
knightEknightCommented:
... the above assumes this:

<FORM name='myform'>
 <SELECT name='myselect'>
  <OPTION></option>
   ...
 </select>
</form>
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
VenkatagiriAuthor Commented:
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.
0
 
VenkatagiriAuthor Commented:
Thanks for your help.  Mine was an ASP VBScript value.  
0
 
knightEknightCommented:
Your welcome, glad it worked!
0
All Courses

From novice to tech pro — start learning today.