473,416 Members | 1,731 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,416 software developers and data experts.

Programmatically Select Option

J1C
If I only know the value of an option is a select list, is it possible
to programmatically select that option?

I would be returning the value from a server-side script ...

Jul 23 '05 #1
4 1943
Lee
J1C said:

If I only know the value of an option is a select list, is it possible
to programmatically select that option?

I would be returning the value from a server-side script ...


How are you returning it? If you're sending the whole page,
just give that option tag the SELECTED attribute.

Jul 23 '05 #2
J1C wrote:
If I only know the value of an option is a select list, is it possible
to programmatically select that option?

I would be returning the value from a server-side script ...


Loop through the options in the select. When you find one with the
required value, set its selected property to true.
function selectOpt( f, s, v ){
var opts = document.forms[f].elements[s].options;
var o, i = opts.length;
while ( ( o == opts[--i] ) ) {
if ( o.value == v ) {
o.selected = true;
return;
}
}
}

If it's a multiple select, drop the return.

--
Fred
Jul 23 '05 #3
Fred Oz wrote:
[...]

function selectOpt( f, s, v ){
var opts = document.forms[f].elements[s].options;
var o, i = opts.length;
while ( ( o == opts[--i] ) ) {


Agghh...

while ( ( o = opts[--i] ) ) {
...

[...]

--
Fred
Jul 23 '05 #4
J1C
thanks all!

Jul 23 '05 #5

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

Similar topics

0
by: Keith | last post by:
Is it possible to modify the file properties of a file programmatically? For example, every file, when you right click has a properties option, then from that you can select the summary tab and...
2
by: Robbie | last post by:
Hi, I want to programatically fire an event. I have it working in IE, but Netscape won't work. What is the Netscape equivalent to, or a workaround for: document.myForm.myField.onchange(); ...
8
by: deko | last post by:
I'm trying to find a way to set form/control properties programmatically. In a nut shell: 1. Open a database 2. Open a form in design view 3. Do something like this: For Each prp In...
2
by: Charles | last post by:
Ok, so I'm creating a form on the fly. I can create the option group, I can create the checkboxes, but I can't figure out how to bind them to the option group I'm creating them within. I was...
2
by: Nicole | last post by:
I am creating template columns programmatically. I have read the msdn article on this and I'm so close. Article:...
32
by: deko | last post by:
I have a popup form with a textbox that is bound to a memo field. I've been warned about memo fields so I'm wondering if I should use this code. Is there any risk with changing the form's...
8
by: William Foster | last post by:
Good evening all, I am creating a program with the ability to select an option from a ComboBox which will then create a secondary list of options in a CheckedListBox. Previously when I have...
5
by: balu435 | last post by:
Hi friends, I have an (VBA) application which programatically fills the options in a web page. I have an dropdown menu whose options are selected during run-time by using a function.Is there...
1
by: rvelosoo | last post by:
Hi, I'm having trouble selecting an option in html, i.e. i change the code, but the change is not reflected in the browser. Example, i have <select> <option>A <option selected>B </selected>
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.