473,887 Members | 2,275 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Dynamically adding <option> tags to <select> boxes in Firefox / IE

Forgive me for I am a bit of a web-dev novice - but I'm not doing too

I'm currently working with a bit of javascript to dynamically add
<option>s into a select box. My code currently works fine in Internet
Explorer, however in Firefox the dropdown only displays the first
option in the list, and when clicked the other values aren't displayed.

Here is the code;

//ar_options is an array with the option to be displayed in.

for (count=0; count<number_of _options+1; count++)
document.forms['enquiry'].enquirytype.op tions[count] = new
Option(ar_optio ns[count],ar_options[count]);

As I said - fine in Internet Explorer, but not in Firefox. I did
discover some discussions about this, which were talking about an issue
and workarounds but I couldn't get any of them to work. I have also
tried simply using the document.write( ) function to output the HTML in
the correct place. However this is just hte same, works in IE but not

Any help would be greatly appreciated.


Dec 21 '05 #1
6 19621

jo************@ gmail.com wrote:
for (count=0; count<number_of _options+1; count++)
document.forms['enquiry'].enquirytype.op tions[count] = new
Option(ar_optio ns[count],ar_options[count]);

I'm assuming you have a form with a name of 'enquiry' and 'enquirytype'
is your select element. In that case, to truly do it dynamically you
can do something like the following example:

var selObj = document.forms["enquiry"].elements["enquirytyp e"];
var option = document.create Element("option ");

for(var count = 0; count < num_of_opt; ++count)
var myOption = option.cloneNod e(false);
myOption.value = ar_options[count];
myOption.append Child(document. createTextNode( ar_options[count]));
selObj.appendCh ild(myOption);

Dec 21 '05 #2
Correct assumptions.

Thanks..... but still no cigar!

Again - it seems work in IE but not FF.

Any ideas? Something with my version or installation of firefox maybe?
Its 1.0.3.


Dec 21 '05 #3
jo************@ gmail.com wrote:
for (count=0; count<number_of _options+1; count++)
document.forms['enquiry'].enquirytype.op tions[count] = new
Option(ar_optio ns[count],ar_options[count]);
and in response to a suggested alternate method,
jo************@ gmail.com wrote:
Correct assumptions.

Thanks..... but still no cigar!

Again - it seems work in IE but not FF.

Any ideas? Something with my version or installation of firefox maybe?
Its 1.0.3.

I say, use the force, Joseph! Does Firefox's Javascript Console indicate
any problems? If so (or if not), use the Document Inspector. Are the options
truly there?

Dec 21 '05 #4
you can access the objects of an option box through DOM.

good page on it at http://www.w3schools.com/htmldom/dom_obj_option.asp

Dec 21 '05 #5
Bah! Humbug.

Well I downloaded the latest ver of Firefox and it works now....

Thanks for the help!

(may the force be with you)

Dec 21 '05 #6

jo************@ gmail.com wrote:
[...] As I said - fine in Internet Explorer, but not in Firefox.

I have written this snippet of hand (look below):

<meta http-equiv="content-type" content="text/html;
<meta name="generator " content="PSPad editor, www.pspad.com">
<script type="text/javascript">
var arr = ["5", "4", "3", "2", "1"];
function change() {

var optsRef = document.forms['f01'].elements['s01'].options;
for(var i=0; i<arr.length; ++i) {
optsRef[i] = new Option(arr[i]);
<form name="f01">
<select name="s01">
<input type="checkbox" onclick="change ();">

, and it perfectly works in FF, IE, Opera, Konqueror...
Maybe it will help.


Dec 21 '05 #7

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

Similar topics

by: Ang Talunin | last post by:
Hey, I wondering if it's possible to retrieve all the <option>-fields from a <select> when posting a <form> to a php file Example: I've got a form like this: <form action = phpfile.php method=post > <select name= "name">
by: LC's No-Spam Newsreading account | last post by:
I have a form arranged in a table (you can see an example in the page http://cosmos.mi.iasf.cnr.it/~lssadmin/Website/LSS/Help/query.html) The table is on three columns but has a structure like this. The part I'm concerned with is the cell FFFFF which contains a multiple <SELECT> list of <OPTION>s. As you can see the first two rows span more than one column (if this has any importance). What I want is to constrain FFFFF not to exceed a...
by: Craig Keightley | last post by:
How do I retrive the Name of the item in a select box I have the following form <select name="select"> <option value="1">Monday</option> <option value="2">Tuesday</option> <option value="3">Wednesday</option> <option value="4">Thursday</option> </select>
by: Iain Hallam | last post by:
Hi. I've been using display:none on the style property of some <option> elements in my forms, which works fine with Mozilla - as expected it removes the option from my dropdown (although it still exists in the code). Is there an equivalent in IE? The reasoning behind this is that I want users to rank objects using a <select> for each place (see below), and to remove the choice of earlier objects from <select> drop-downs later in the...
by: Bonge Boo! | last post by:
This has got to be obvious, but I can't make it work. I have a form called with 3 pull down menus. They are linked to a database which generates the values for the <SELECT? Pull-downs. Lets say I have values selected for all three pull down menus. When I change the first "top-level" menu I want to reset both the second and third menus to the "default" state.
by: bb nicole | last post by:
Below is the list menu of search engine.. How to code if i want to put <option selected>ALL</option> Interface <tr> <td>Job Category:</td> <td><select name="jobCategory"> <option selected></option>
by: otiose3 | last post by:
I've been ploughing through the archives here, but I can't seem to find a solution for my situation... Essentially, I want to run the JQuery script that is in the "value" attribute of my <option> tags, when they are selected. I know to use onchange="" and probably 'this', but how do I get the string in the value tag to run as a function? <select name="Add Criteria" onchange=""> <option...
by: sreemathy2000 | last post by:
I have the below code in the form for the select dropdown in my web page. how can i get the selected text from javascript. i was able to get the value, but text shows as undefined. <SELECT name="queue" id="queue"><OPTION selected value="0">Select reason</OPTION><option value="Residential Tier 1 Chat" text="Account Information">Account Information</option><option value="NEW Residential Tier 1 Chat" text="Billing Inquiry">Billing...
by: mikek12004 | last post by:
In a form I have 5 elements (e.g. pictures) and I wish for the user to be able to set the order of appearance. For this I have for each picture a select box (names select1 to select5) with "please select something" as preselected and the rest options are values from 1 to 5. I want when a user selects a number a.k.a ans <option> that number/<option> to be removed from the rest of the select boxes and when the user selects another number the...
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
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: 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: 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: 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: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.