473,385 Members | 1,483 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

accessing select object via value

Hi all,

I've got a situation where I have a given string and I need to find
which option in a select object has a value matching this string. I know
I could do it by iterating through all of the options and comparing my
string to the value of each, but what I am wondering is...

Is there anyway to access the values of options in a select object as
though they were keys in an associative array, something like:

myForm.mySelect.myOption['such-and-such'].index -- returns the index of
such-and such

I know there are a zillion reasons why this particular example doesn't
work, but is there any way to do this without iterating through the
array?

Many thanks,
sp
Jul 20 '05 #1
2 2023
Steven Post wrote:
Hi all,

I've got a situation where I have a given string and I need to find
which option in a select object has a value matching this string. I know
I could do it by iterating through all of the options and comparing my
string to the value of each, but what I am wondering is...

Is there anyway to access the values of options in a select object as
though they were keys in an associative array, something like:

myForm.mySelect.myOption['such-and-such'].index -- returns the index of
such-and such

I know there are a zillion reasons why this particular example doesn't
work, but is there any way to do this without iterating through the
array?

Many thanks,
sp


If you set the ID (or possibly the NAME attr, but I would stick to ID)
attribute in the option to be the same as the value, then you can do
what you are talking about. If not, you will need to itterate.

Also, if you do what I said, and the string does _not_ exist, you will
likely get a failure, so you will need to do error checking, unless you
know the string will _always_ be one of the options. Your best bet
might be to itterate through the options. As long as you dont have many
options, this will not take much time.

B

Brian

Jul 20 '05 #2
In article <3F**************@yahoo.com>,
Brian Genisio <Br**********@yahoo.com> wrote:
If you set the ID (or possibly the NAME attr, but I would stick to ID)
attribute in the option to be the same as the value, then you can do
what you are talking about. If not, you will need to itterate.

Also, if you do what I said, and the string does _not_ exist, you will
likely get a failure, so you will need to do error checking, unless you
know the string will _always_ be one of the options. Your best bet
might be to itterate through the options. As long as you dont have many
options, this will not take much time.


I'll give that a shot. Thanks.

sp
Jul 20 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Jason | last post by:
this is my code and what i get... i'm accessing this through this url http://192.168.0.2/php/test2/test.php?user=me@test.ca&subject=test it grabs the correct stuff from the database, but...
3
by: rosemm | last post by:
I am having a problem accessing an element in an XML document (one that I receive from someone else). The xml looks like this <FAMILY> <DAD> <ADDRESS> <ADDRESS_LINE VALUE="SOMETHING"/>...
1
by: Terry A. Haimann | last post by:
First of all be kind, I am new to javascript. In the following page, can you tell me if I have defined the ObjTyp and the ObjTypeCnt incorrectly. And if that is correct, why can't they be seen...
4
by: stjulian | last post by:
I have a stored procedure that is supposed to 1. Increment a counter in Table A via a transaction 2. Use this value as the primary key to add in an address to customers Table B (Referenced as a...
6
by: Chris Styles | last post by:
Dear All, I've been using some code to verify form data quite happily, but i've recently changed the way my form is structured, and I can't get it to work now. Originally : The form is...
1
by: RFS666 | last post by:
Hello together, I wanted to ask if somebody can help me with accessing a listbox (a serverside webform from the designer-toolbox) from clientside JScript. I need to add and remove values and...
7
by: skeddy | last post by:
In a nutshell, I'm trying to dynamically create a select box with ResultSet code in vbscript and then need to be able to access the value of that select box later with a Save button. I've got...
7
by: Chuck Anderson | last post by:
I'm pretty much a JavaScript novice. I'm good at learning by example and changing those examples to suit my needs. That said .... ..... I have some select fields in a form I created for a...
6
by: Chuck Anderson | last post by:
My knowledge of JavaScript is limited. I learn from example and then adapt those examples to suit my needs. I have stumped myself on this one. I have a form with checkboxes that I want to...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.