473,513 Members | 2,519 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Firefox and select lists

Hi,

I have two select lists and depending on the value selected in the
first select dropdown, I want to populate the second list.

I tired a couple of different ways, but for some reason, it works fine
on IE but not on Firefox. On Firefox the second dropdown list doesnt
get populated.

Any pointers on how to populate the second dropdown..

Heres the code:-

for(var j=0;j<array.length;j++)
{
this.document.getElementById("secondSelectName").o ptions[j] = new
Option("txt", "val");
}

for(var j=0;j<array.length;j++)
{
var oOption = document.createElement("OPTION");
secondSelectlist.options.add(oOption);
oOption.innerText = "txt";
oOption.value = "value";
}

for(var j=0;j<array.length;j++)
{
this.document.getElementById("secondSelectName").a dd(new Option("txt",
"val"));
}

Thanks for the inputs,
Beena

Feb 6 '06 #1
4 7910
be*******@gmail.com said the following on 2/6/2006 1:32 PM:
Hi,

I have two select lists and depending on the value selected in the
first select dropdown, I want to populate the second list.
Ummm, ok.
I tired a couple of different ways, but for some reason, it works fine
on IE but not on Firefox. On Firefox the second dropdown list doesnt
get populated.
Really? Considering you have some really, ummm, weird code that doesn't
surprise me.
Any pointers on how to populate the second dropdown..

Heres the code:-
And where is that code at? And where is the HTML that goes with it?
for(var j=0;j<array.length;j++)
{
this.document.getElementById("secondSelectName").o ptions[j] = new
Option("txt", "val");
}
Using gEBI to access form elements? First guess, your form elements have
NAME attributes and not ID attributes.
for(var j=0;j<array.length;j++)
{
var oOption = document.createElement("OPTION");
secondSelectlist.options.add(oOption);
oOption.innerText = "txt";
..innerText is IE only.
oOption.value = "value";
}

for(var j=0;j<array.length;j++)
{
this.document.getElementById("secondSelectName").a dd(new Option("txt",
"val"));
}

Thanks for the inputs,


Post a URL to a sample page that has your *complete* code in it. The
above is next to useless to try to figure out why it doesn't "work".

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Feb 6 '06 #2
be*******@gmail.com wrote :
Hi,

I have two select lists and depending on the value selected in the
first select dropdown, I want to populate the second list.

I tired a couple of different ways, but for some reason, it works fine
on IE but not on Firefox. On Firefox the second dropdown list doesnt
get populated.

Any pointers on how to populate the second dropdown..

Heres the code:-

for(var j=0;j<array.length;j++)
{
this.document.getElementById("secondSelectName").o ptions[j] = new
Option("txt", "val");
}

for(var j=0;j<array.length;j++)
{
var oOption = document.createElement("OPTION");
secondSelectlist.options.add(oOption);
HTML select have an add method but not options.

http://www.w3.org/TR/DOM-Level-2-HTM...ml#ID-14493106

Also, the W3C DOM 2 HTML add method takes 2 parameters, not 1.

MSIE 6 does not support
objSelect.add(objOption, null)

Proven workaround:
objSelect.appendChild(objOption);

oOption.innerText = "txt";
oOption.appendChild(document.createTextNode("txt") );

As mentioned by Randy, innerText is a proprietary property.
oOption.value = "value";
}

for(var j=0;j<array.length;j++)
{
this.document.getElementById("secondSelectName").a dd(new Option("txt",
"val"));


I'm not sure you can do the above statement. Can you post an url?

Gérard
--
remove blah to email me
Feb 7 '06 #3
be*******@gmail.com wrote:
Hi,

I have two select lists and depending on the value selected in the
first select dropdown, I want to populate the second list.

I tired a couple of different ways, but for some reason, it works fine
on IE but not on Firefox. On Firefox the second dropdown list doesnt
get populated.

Any pointers on how to populate the second dropdown..

Heres the code:-

for(var j=0;j<array.length;j++)
{
this.document.getElementById("secondSelectName").o ptions[j] = new
Option("txt", "val");
}

for(var j=0;j<array.length;j++)
{
var oOption = document.createElement("OPTION");
secondSelectlist.options.add(oOption);
oOption.innerText = "txt";
oOption.value = "value";
}

for(var j=0;j<array.length;j++)
{
this.document.getElementById("secondSelectName").a dd(new Option("txt",
"val"));
}


IE has trouble adding otpions using createElement. The best way (i.e.
supported in most browsers) to add options to a select element is with
new Option (wrapped for posting):

selRef(selRef.options.length) =
new Option([text, [value, [defaultSelected, [selected]]]])
Where all parameters are optional and:

text is the option text
value is the default value
selected is a boolean (true/false) to make the option selected
defaultSelectedis a boolean to make the option the default selected

new Option() is DOM 0, so widely supported and likely never to be dropped.

e.g.
<script type="text/javascript">
function addOptions(sel)
{
// Remove existing options
sel.options.length = 0;

// Add 5 options, make opt index 2 default selected and 4 selected
for (var i=0; i<5; ++i){
sel[sel.options.length] =
new Option('Option ' + i, 'opt' + i, (i==2), (i==4) );
}
}
</script>

<form action="">
<select name="selA">
<option selected></option>
</select>
<input type="button" value="Add options"
onclick="addOptions(this.form.selA);">
<input type="reset">
</form>

--
Rob
Feb 7 '06 #4
iwan
1 New Member
I have same problem with my firefox browser which is the default selected value in = new Option([text, [value, [defaultSelected, [selected]]]]) are not functionaly properly, even the value has been set to true
May 19 '06 #5

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

Similar topics

6
2466
by: R. Rajesh Jeba Anbiah | last post by:
In IE, I could be able to directly refer the "id", but it isn't possible in Firefox. Somewhere I read the solution is to refer the id like document.getElementById("month") in Firefox. If I do so,...
2
9777
by: Chuck Martin | last post by:
I am having a most frustrating problem that references, web searches, and other resources are no help so far in solving. Basically, I'm trying to design a pop-up window to be called with a funciton...
6
3013
by: Sjaakie | last post by:
Hi there, I'm trying to get this working with Firefox. Can you point out what's wrong? No problems with IE, Firefox doens't fill selMonth... TIA >>> the script... >>> <select name="selDay"...
10
12880
by: Alan Silver | last post by:
Hello, In my (seemingly) endless quest to understand CSS, I have yet another problem. Please look at http://www.kidsinaction.org.uk/ph/x.html in Opera, where you will see it how I expected. If...
2
17071
by: cbjewelz | last post by:
Hey all. So I'm having problems with cross browser alignments. I'm looking at Safari and Mozilla Firefox. I develop in Safari and so it looks perfect there however in Firefox my vertical...
2
2014
by: StephenM | last post by:
I am looking for an answer to what might either be a very common problem or something specific to Mozilla Firefox users. Let me explain... A few days ago I noticed an interesting anomoly:...
11
2792
by: davecph | last post by:
I'm constructing a website with a layout created with div-tags. They have a fixed width, float left, and display inline. When one of the div's contain a select-element the right-most div floats down...
11
2180
victorduwon
by: victorduwon | last post by:
Hey guys, I have built a suckerfish navigation menu using CSS and HTML with unordered lists. I was testing this menu in Safari, and it came out good. When I finished I tested it in firefox and...
4
5348
by: Patrick Nolan | last post by:
I am using javascript to manipulate optgroups in select elements. When the results are displayed in Firefox 2.0 there is an annoying blank line at the top of the multi-line select box. This...
0
7260
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
7384
Oralloy
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,...
0
7537
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...
1
7099
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...
0
7525
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...
0
5685
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,...
0
4746
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...
0
1594
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 ...
0
456
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...

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.