473,655 Members | 3,072 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

select elements

2 New Member
Hi gurus,

I have following code:
Expand|Select|Wrap|Line Numbers
  1. <select id="edit-field-color-tids" class="form-select" multiple="multiple" name="field_color[tids][]">
  2.     <option value="362">ffcedc</option>
  3.     <option value="363">ffdebe</option>
  4.     <option value="364">fff5c5</option>
  5.     <option value="365">e1ffd8</option>
  6.     <option value="366">bff7ff</option>
  7.     <option value="367">e7cdff</option>
  8.     <option value="368">f7f4ee</option>
  9.     <option value="369">ffffff</option>
  10.     <option value="370">ff8aab</option>
  11. </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
Jan 5 '08 #1
5 1778
abarak
1 New Member
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:
Expand|Select|Wrap|Line Numbers
  1. <select id="edit-field-color-tids" class="form-select" multiple="multiple" name="field_color[tids][]">
  2.     <option value="362">ffcedc</option>
  3.     <option value="363">ffdebe</option>
  4.     <option value="364">fff5c5</option>
  5.     <option value="365">e1ffd8</option>
  6.     <option value="366">bff7ff</option>
  7.     <option value="367">e7cdff</option>
  8.     <option value="368">f7f4ee</option>
  9.     <option value="369">ffffff</option>
  10.     <option value="370">ff8aab</option>
  11. </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
Jan 6 '08 #2
chaarmann
785 Recognized Expert Contributor
First, give a better name, or you will have BIG problems in javascript.
Expand|Select|Wrap|Line Numbers
  1. name="field_color[tids][]" 
is not acceptable! Use
Expand|Select|Wrap|Line Numbers
  1. name="field_color" 
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):
Expand|Select|Wrap|Line Numbers
  1. var selectBox = document.getElementById("field_color");
  2. selectBox.options[3].selected = true;
Jan 6 '08 #3
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):
Expand|Select|Wrap|Line Numbers
  1. var selectBox = document.getElementById("field_color");
  2. selectBox.options[3].selected = true;
...or use selectBox.selec tedIndex = 3.
Jan 7 '08 #4
mixey
2 New Member
Thank you guys for the help! You helped me out A LOT!
Jan 13 '08 #5
acoder
16,027 Recognized Expert Moderator MVP
You're welcome. Post again if you have any more questions.
Jan 14 '08 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

4
6431
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
12
6533
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
0
4064
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...
12
8869
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>
15
15453
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
3
2653
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. ...
2
2269
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...
17
17045
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
2
2771
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-->
0
8710
jinu1996
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...
1
8497
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
8598
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...
1
6162
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
5627
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
4150
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
4299
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2721
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
2
1598
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.