Smart questions
Smart answers
Smart people
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

Join Tek-Tips
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

LINK TO THIS FORUM!

Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

Partner With Us!

"Best Of Breed" Forums Add Stickiness To Your Site
Partner Button
(Download This Button Today!)

Feedback

"...I just want to say how much I value your site. I hope the good work keeps up there. It's really helped me..."

Geography

Where in the world do Tek-Tips members come from?

Loop through options in a select

tackaman (IS/IT--Management)
4 Jul 12 22:15
I have a subroutine that dynamically adds options to a select based on data entered into a number of text boxes. Everything works great except I need to change my sub to check the options that are in the select to see if it exists before adding the value. In other words, I don't want to duplicate the options in the select.

Can anyone provide sample code to loop through the options in a select and compare the values to the values in my text box?
Geates (Programmer)
5 Jul 12 9:32
I assume you are referring to a HTML select element?

CODE --> html

<select id="names">
	<option value="Bill">Bill</option>
	<option value="Jack">Jack</option>
	<option value="Mary">Mary</option>
</select> 

CODE --> vbs

set objOptions = document.getElementById("names")
for each objOption in objOptions
   msgbox objOption.value
next 

Of course, this will only work when executed by IE. Non-IE browsers do not support VBS. If you need it to be cross-browser compatable, I recommend using javascript - the code is essentially the same.

- Geates



"I hope I can chill and see the change - stop the bleed inside and feel again. Cut the chain of lies you've been feeding my veins; I've got nothing to say to you!"
-Infected Mushroom

"I do not offer answers, only considerations."
- Geates's Disclaimer

SkipVought (Programmer)
9 Jul 12 11:02
Or could it be a Select CASE structure?

Skip,

glassesJust traded in my old subtlety...
for a NUANCE!tongue

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Back To Forum

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close