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?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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
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
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

knightEknightCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
VenkatagiriAuthor Commented:
Thanks for your help.  Mine was an ASP VBScript value.  
0
knightEknightCommented:
Your welcome, glad it worked!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
HTML

From novice to tech pro — start learning today.