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

How do you populate the 'select box' using an array?

135 100+
Currently my code looks like this?

<select Name=loc>
<option Name=Eng value ="England">England</option>
<option Name=Sco value ="Scotland">Scotland</option>
<option Name=Wal value ="Wales">Wales</option>
<option Name=Ire value ="Ireland">Ireland</option>
</select>

Cheers
Aug 6 '07 #1
7 3710
acoder
16,027 Expert Mod 8TB
Use the select element's add method.

Loop through the array using a for loop.
Aug 7 '07 #2
patelxxx
135 100+
Acoder,

Sorry mate I didn't understand the add(), Can you start me start or give me another example, again what I'm trying to do is:

use a javascript array to populate the select list box, making the first element 'Select...

Many Thanks
Aug 7 '07 #3
acoder
16,027 Expert Mod 8TB
Acoder,

Sorry mate I didn't understand the add(), Can you start me start or give me another example
What do you not understand about the example? It's a very simple example which creates an option element, sets the text to 'Kiwi' (though should set the value too) and then adds to the select element.

Give it a try by copying and modifying the code. If you get stuck, post the problem code here.
Aug 7 '07 #4
patelxxx
135 100+
That example was fine, however how would I populate the list using 'Loops'.

Cheers
Aug 9 '07 #5
acoder
16,027 Expert Mod 8TB
That example was fine, however how would I populate the list using 'Loops'.

Cheers
Put the code in insertOption into a 'for' loop. Loop over the array and replace 'Kiwi' with the indexed array value:
Expand|Select|Wrap|Line Numbers
  1. for (i = 0; i < arr.length; i++) {
  2. ...
  3. y.text = arr[i];
  4. ...
  5. }
Aug 9 '07 #6
patelxxx
135 100+
Thank you mate got this working now.
Aug 13 '07 #7
acoder
16,027 Expert Mod 8TB
Thank you mate got this working now.
No problem, you're welcome.
Aug 13 '07 #8

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

Similar topics

3
by: deko | last post by:
I have an html drop-down list (they're called combo boxes in vb, not sure what they're called in html): <select name="ipSelect" size="1" style="width:140px;"></select> The user is supposed to...
2
by: C. David Rossen | last post by:
Hello: I have a registration form for classes. Each class has a fee. I have a drop down box whereby the user chooses his class. There is a textbox with the associated fee. I would like to...
6
by: Greg Scharlemann | last post by:
I am attempting to populate a drop down menu based on the selection of a different drop down menu. However, it is not working correctly, I cannot figure out for the life of me what exactly happens...
2
by: James Goodman | last post by:
I have a listbox named sub1 on an asp page. I need to fill this list with values from a table. These are selected based upon the selection of a value/s in another listbox. It was suggested that I...
1
by: Grant Hammond | last post by:
I have a callback function that populates a listbox with a list of file names in a folder. This code came from Terry Kreft/Dev Ashish some years ago. I now want to add another column to the list...
2
by: Dave McKie | last post by:
Hi all I am trying to Populate a combo box from a selection in an adjacent Listview. The Listview lists as a string the field names of 4 different fields in tblFile. So far I can populate the...
1
by: indhu | last post by:
Hi all, I want 2 know, how to populate using 2 combo box to populate other field. right now am using click event of combo to populate the other field but i want to select both combo1 and combo2 ...
4
by: whamo | last post by:
I have the need to populate a field based on the selection in a combo box. Starting out simple. (2) tables tbl_OSE_Info and tbl_Input; tbl_OSE_Info has three fields: Key, OSE_Name and OSE_Wt...
5
by: giandeo | last post by:
Hello Experts. Could you find a solution for this problem please! I have the following tables in Access Database Table Name: origin Fields Names: country, countrycode Table Name: make...
3
by: fishctr | last post by:
Hi There, I am creating a survey that asks users what countries they have worked in, and which regions in those countries. Because there can be many answers, I was thinking I could populate a...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
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...
0
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...

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.