Hi gurus,
I have following code: - <select id="edit-field-color-tids" class="form-select" multiple="multiple" name="field_color[tids][]">
-
<option value="362">ffcedc</option>
-
<option value="363">ffdebe</option>
-
<option value="364">fff5c5</option>
-
<option value="365">e1ffd8</option>
-
<option value="366">bff7ff</option>
-
<option value="367">e7cdff</option>
-
<option value="368">f7f4ee</option>
-
<option value="369">ffffff</option>
-
<option value="370">ff8aab</option>
-
</select>
And I'm curious is there any way to select elements in the select list with javascript help? Basically I would like get same result as I would get if I have used CTRL+click with mouse.
But I need to do that without actually pressing the select list.
I hope my explanation is clear,
looking forward and thanks in advance
5 1778
If it is before you render the markup, add 'selected' in the items you want selected, e.g:
<option value="364" selected>fff5c5 </option>
(Not JavaScript really, just HTML)
If the list is already part of your document tree you may need to alter it, i.e. locate the DOM element node of the option you need to select, and modify the innerHTML value. i usually assign a unique id to the whole list and use prototype.js framework $(<element id>).update(<ne w markup>).
Cheers!
Hi gurus,
I have following code: - <select id="edit-field-color-tids" class="form-select" multiple="multiple" name="field_color[tids][]">
-
<option value="362">ffcedc</option>
-
<option value="363">ffdebe</option>
-
<option value="364">fff5c5</option>
-
<option value="365">e1ffd8</option>
-
<option value="366">bff7ff</option>
-
<option value="367">e7cdff</option>
-
<option value="368">f7f4ee</option>
-
<option value="369">ffffff</option>
-
<option value="370">ff8aab</option>
-
</select>
And I'm curious is there any way to select elements in the select list with javascript help? Basically I would like get same result as I would get if I have used CTRL+click with mouse.
But I need to do that without actually pressing the select list.
I hope my explanation is clear,
looking forward and thanks in advance
First, give a better name, or you will have BIG problems in javascript. - name="field_color[tids][]"
is not acceptable! Use
only!
Then you can select elements in the list with following code, which for example selects the element at index 3 (=fourth element of box): - var selectBox = document.getElementById("field_color");
-
selectBox.options[3].selected = true;
acoder 16,027
Recognized Expert Moderator MVP
Then you can select elements in the list with following code, which for example selects the element at index 3 (=fourth element of box): - var selectBox = document.getElementById("field_color");
-
selectBox.options[3].selected = true;
...or use selectBox.selec tedIndex = 3.
Thank you guys for the help! You helped me out A LOT!
acoder 16,027
Recognized Expert Moderator MVP
You're welcome. Post again if you have any more questions.
Sign in to post your reply or Sign up for a free account.
Similar topics |
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
|
by: Kevin Lyons |
last post by:
Hello,
I am trying to get my select options (courses) passed correctly from
the following URL: http://www.dslextreme.com/users/kevinlyons/selectBoxes.html
I am having difficulty getting the courses to pass the correct option
value and then be displayed at the following URL:
http://www.dslextreme.com/users/kevinlyons/selectResults.html
I am passing countries, products, and courses. The first two display
|
by: Francis Parsons |
last post by:
Hi! I'm doubtful there's a workaround for this problem, but it's
worth a shot. I'm using IE's (css) "zoom" property to zoom the body
of a document (in conjunction with persistance so the previously
selected percentage level is restored each time the page is reloaded).
I don't expect zoomed images to look perfect, but overall the quality
of the zooming is pretty good (as good as Opera's ;-) EXCEPT for any
<select> elements, which are...
|
by: Forti2ude |
last post by:
Hello,
I have a simple form...
<form>
<select name="foo" multiple>
<option value="1">one</option>
<option value="2">two</option>
<option value="3">three</option>
</select>
|
by: TJ Walls |
last post by:
Hello All,
Is it possible to create a <select> element with no selected options? I
have tried setting the selectedIndex attribute to -1, but as far as I can
tell this only works for <select multiple> elements.
Am I missing something obvious?
Sincerely,
TJ Walls
| |
by: larry |
last post by:
Hi,
I am a newbie to Internet programming. I have some questions about
spacing in HTML control names and subsequently being able to access
these input elements in JavaScript If you don't have time to read the
whole message, the main question is can HTML form names have spaces in
them and if so what is the syntax for accessing them using Javascript
I have a Perl script which dynamically creates html and ultimately
generates a form. ...
|
by: dinkle |
last post by:
Hi Y'all,
I am pretty new to js and am hitting a few snags. I need to process a multiple select list and pass it onto a PHP script.
I can only get the first value in the JS and have no idea how to grab the rest and successfully pass the array onto my php script.
No books, foums, examples, tutorials or anything I have spent most of my recent waking hours reading and downtime dreaming about appear to cover this and I am starting to think...
|
by: Sam Kong |
last post by:
Hello,
There are 1 or more select elements with the same name in a form.
Let's say that the name of the select is 'select1' and the name of the
form is 'form1'.
If there's only one select I access it like form1.select1.
If there are more than one select, I access them like
form1.select1.
To check if there are more than one, I thought I can use
|
by: helplakshmi |
last post by:
Hi All,
I am new to php. The form that i am designing has few input input fields with submit and reset button. The functionality of submit and reset are working properly till now.
My form
<form name="search" id="search" action= "search.php" method = "post" onreset="formReset(this);return false;">
<table cellspacing="1" cellpadding="1" >
<tr> <!-- Input field for responsible-->
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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,...
| |
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...
|
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...
|
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();...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
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...
| |