473,698 Members | 2,601 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

select an option


hi,
how do you select an option using javascript?

i tried to setAttribute("s elected", "disabled") to disable last
selected and setAttribute("s elected", "selected") for the newly selected.

doesnt work :)

the last option in the list is always selected no matter which value
"selected" has.

greetings from Aachen,

Sebastian
Feb 6 '08 #1
2 2381
On Feb 6, 12:24 pm, Sebastian Fey <sebastian....@ web.dewrote:
hi,

how do you select an option using javascript?

i tried to setAttribute("s elected", "disabled") to disable last
selected and setAttribute("s elected", "selected") for the newly selected.

doesnt work :)

the last option in the list is always selected no matter which value
"selected" has.

greetings from Aachen,

Sebastian
Try obj.getAttribut e("selected") first. What do you get as a result of
this call?
Now, do you see why your code does not work?
Feb 6 '08 #2
On Feb 6, 10:24 pm, Sebastian Fey <sebastian....@ web.dewrote:
hi,

how do you select an option using javascript?

i tried to setAttribute("s elected", "disabled") to disable last
setAttribute sets the HTML selected attribute, not the DOM element's
selected property. Just don't use setAttribute, set properties
directly.

Also, the selected attribute is set to boolean true or false, not some
string value so use:

someOption.sele cted = false;

to "unselect" an option. If the select element's selectedIndex
property is set to -1, or all the options' selected properties are set
to false, no options will be selected.

selected and setAttribute("s elected", "selected") for the newly selected.

doesnt work :)
That is equivalent to the HTML <option selected ... which probably
has no effect on the currently selected option. Use:

someOtherOption .selected = true;

the last option in the list is always selected no matter which value
"selected" has.
You can either set the selectedIndex property of the select element,
or the selected property of a particular option element. There is no
need (in a single select) to set any other option's selected property
to false.

Things are a little different in a multiple-select.
--
Rob
Feb 6 '08 #3

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

Similar topics

1
5254
by: JT | last post by:
I have an input form for which I've created a "matrix" for user input. Basically, the user chooses a radio button and then through javascript, a select box is displayed to define a value for that radio option, like so: Choice: (Radio1) type: (select box1) Choice: (Radio1) type: (select box2) Choice: (Radio1) type: (select box3) Choice: (Radio1) type: (select box4) Choice: (Radio1) type: (select box5)
4
6437
by: point | last post by:
Hello there... I'm a PHP programmer and starting to learn JS... I have a following problem.... I have 3 select boxes! one is hotel one is destination and one is country... if someone clicks selects the country then the destination select box shows the destinations in that country and further if he chooses destination all
3
16434
by: gekoblu | last post by:
Hi!, I want to fix via javascript the combo width to a fix value. I'd like to implement a kind of ALT / TITLE function to show the entire option when the text is longer than the combo width... It's possible?!? Thanks
4
3865
by: Marek Mänd | last post by:
This seems an IE issue only: 4253 bytes testcase: http://www.hot.ee/idaliiga/testcases/ieselect/bnlinkingselectinmsie.htm Can one have 1) a mouseover/mouseout element on TBODY 2) change in thoise event handler background colors 3) have a specified heighted SELECT element, that doesnt flicker when the event handlers are get called.
6
4294
by: Ben Hallert | last post by:
Hi guys, I'm trying to figure out what bone headed mistake I made on something I put together. I've got a form (named 'context') that has a variable number of select-multiple inputs on it. Based on the number of variables passed through a GET string, I want to multiply the total number of selected items for each together to see how many possible combinations the selected items are generating. The following snippet of code...
5
2383
by: callmebill | last post by:
I'm relatively new to javascript, and I'm trying to decide whether the following (and if so, clues on how to do it): I'd like to create two HTML multiple-select boxes. The first would be a list of items, and the second would be a list of categories. By clicking a category in the 2nd box, the members of that category (from the first box) would be highlighted (indicated here by arrows). E.g., -- List of Nums -- -- Categories -- 1...
9
51984
chunk1978
by: chunk1978 | last post by:
hey everyone, i've been trying to solve this problem for 2 days straight, with no end in sight. i would greatly appreciate anyone's help. EXPLANATION: There are 3 Select Menus. The 1st and 2nd Select Menu are "printing options" for 4x6 and 5x7 prints respectively. the 3rd Select Menu holds an "Email" option that can be toggled (appear/reappear) by the 1st and 2nd Select Menus. So if a user selects prints from either 4x6 or 5x7 menu,...
7
6232
by: srt5k | last post by:
I have a web page with 2 html multiple select boxes on it, and I use javascript to dynamicaly copy options from one box to another, before deleting the option from the first box. My issue is that in IE 7 more often than not after the option value has been deleted form.selone.options = null; the select box resets to the first item in the list, meaning that the
2
2575
by: Tarik Monem | last post by:
OK! I've gone through a few tutorials and I cannot understand what I'm doing wrong casting_registration.php <table> <tr> <td> <form enctype="multipart/form-data" action="thankyou.php" method="post" name="registrationform"> Choose a shows:
2
1732
by: Sudhakar | last post by:
i have two select tags as part of a registration form, city1 city2 where city1 has a list of regions and similar for city2 there are different regions for city1 and city2 so instead of all the regions appearing one after the other i would like to create a blank option followed by the next set of regions for formatting purpose only. ex= <select name="city1">
1
8904
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8876
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7741
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6531
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5867
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4372
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4624
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2341
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2007
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.