473,804 Members | 3,515 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Combo box onChange not working in Firefox

Hi all,
I have written a javascript code which changes the combo_2 options on
runtime. It is working fine on IE but not working on Firefox. Please
help me solve this problem.

My code is as follows:

function changeMe(str) {
if(str.value == "se") {
while(document. frm.combo2.leng th 0) {
document.frm.co mbo2.remove(0);
}
var y;
y = document.create Element('option '); y.text='ONE-1';
y.value="one-1";
document.frm.co mbo2.add(y, 0);

y=document.crea teElement('opti on'); y.text='one-2'
document.frm.co mbo2.add(y, 0);
}
}
<form name="frm">
<select id="combo1" onChange="chang eMe(this)">
<option value="se">Sony Erricson</option>
<option value="c2">C2</option>
</select>

<select name="combo2">
<option value="b1">B1</option>
<option value="b2">B2</option>
</select>
</form>

Kindly suggest me what am i doing wrong?

Thanks

Apr 24 '07 #1
5 10109
On Apr 24, 1:23 am, atu...@gmail.co m wrote:
Hi all,
I have written a javascript code which changes the combo_2 options on
runtime. It is working fine on IE but not working on Firefox. Please
help me solve this problem.

My code is as follows:
....
document.frm.co mbo2.add(y, 0);
document.frm.co mbo2.add(y, 0);
....

0 is not valid for 2nd parameter in Firefox. Pass a reference to an
option element in 2nd element e.g.
document.frm.co mbo2.add(y,docu ment.frm.combo2 .options[0])
Apr 24 '07 #2
On Apr 24, 2:54 pm, "scripts.contac t" <scripts.cont.. .@gmail.com>
wrote:
[...]
>
0 is not valid for 2nd parameter in Firefox. Pass a reference to an
option element in 2nd element e.g.
document.frm.co mbo2.add(y,docu ment.frm.combo2 .options[0])
Thanks this works but not working on IE. Any suggetion to work on all
browsers.

Regards

Apr 24 '07 #3
On Apr 24, 4:18 am, atu...@gmail.co m wrote:
0 is not valid for 2nd parameter in Firefox. Pass a reference to an
option element in 2nd element e.g.
document.frm.co mbo2.add(y,docu ment.frm.combo2 .options[0])

Thanks this works but not working on IE. Any suggetion to work on all
browsers.
try:

function changeMe(str) {
if(str.value == "se") {
var Combo2=document .frm.combo2,y
while(Combo2.op tions.length)
Combo2.remove(0 );

y = document.create Element('option ');
Combo2.appendCh ild(y)
y.text='ONE-1';y.value="one-1";

y=document.crea teElement('opti on');
Combo2.appendCh ild(y);
y.text='one-2';
}
}

Apr 24 '07 #4
On Apr 24, 3:47 pm, "scripts.contac t" <scripts.cont.. .@gmail.com>
wrote:
On Apr 24, 4:18 am, atu...@gmail.co m wrote:
[...]
>
y = document.create Element('option ');
Combo2.appendCh ild(y)
y.text='ONE-1';y.value="one-1";

y=document.crea teElement('opti on');
Combo2.appendCh ild(y);
y.text='one-2';
}

}
Thanks for Help

Apr 24 '07 #5
On Apr 24, 5:23 pm, atu...@gmail.co m wrote:
Hi all,
I have written a javascript code which changes the combo_2 options on
runtime. It is working fine on IE but not working on Firefox. Please
help me solve this problem.

My code is as follows:

function changeMe(str) {
if(str.value == "se") {
while(document. frm.combo2.leng th 0) {
document.frm.co mbo2.remove(0);
}
To remove all the options, set the length of the options property to
zero:

document.frm.co mbo2.length = 0;

var y;
y = document.create Element('option '); y.text='ONE-1';
y.value="one-1";
You can declare and initialise y in one go. Also, using createElement
is somewhat buggy in IE, so use:

var y = new Option('ONE-1', 'one-1');

or

var y = document.create Element('option ');
y.value="one-1";
y.appendChild(d ocument.createT extNode('ONE-1'));

but the first method seems so much simpler.

document.frm.co mbo2.add(y, 0);

y=document.crea teElement('opti on'); y.text='one-2'
document.frm.co mbo2.add(y, 0);
}

}

<form name="frm">
<select id="combo1" onChange="chang eMe(this)">
Using onchange is likely not a good idea. Try it in IE and use the
cursor keys to move down the options, as would someone using the
keyboard rather than a mouse. Compare that to what happens in Firefox
doing the same thing.
--
Rob

Apr 24 '07 #6

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

Similar topics

4
6138
by: Bart van Deenen | last post by:
Hi all I have a script where I dynamically create multiple inputs and selects from a script. The inputs and selects must have an associated onchange handler. I have the script working fine on Firefox, Safari and Konqueror, but the onchange event just doesn't fire on IE6. Firefox's javascript console shows no errors, and the IE script debugger shows nothing. onchange is not triggered.
3
4321
by: vgrssrtrs | last post by:
<html> <head> <script language="JavaScript"> <!-- /* *** Multiple dynamic combo boxes *** by Mirko Elviro, 9 Mar 2005 *** ***Please do not remove this comment
2
5475
by: Sean | last post by:
Greetings all, I am attempting to make a form that will filter through several tables that (I believe) have refretial integrity. I am pulling data from several tables into the form and i would like to eventually be able to filter down through the tables untill i can reach one unique record. I am creating a datbase to keep track of registered accounts for a stae program. Each account is registered into the program through a two...
3
2208
by: Antoine Janssen | last post by:
hi, I would like to create two combo boxes. In the first one you can select a user in the second one you can select a project. To simplify the selection i would like to shorten the project list by just presenting the projects the selected user is working on (using a where clause with the userid filled in). Does onyone know how to achieve this? Kind Regards,
3
3989
by: jab3 | last post by:
Hello. I"m new to this group, and to JavaScript in general, so please forgive me if I breach local etiquette. I'm trying to implement some client-side 'dynamic' validation on a form. I'm having a couple of problems, which I'll try to describe. But this e-mail will only reproduce one of them, in a "short" example. What I'm generally doing is having each form entry contained in a div, which as a label, an input with some event handlers,...
33
5567
by: buss123 | last post by:
Hi all, combo box script code was working in IE perfectly with all modes but OnChange event was not working in FireFox(editable mode, if we select valuese that combo box values r not dislaying if enter the data the it is inserting properly) javascript code follows pls help me to solve this problem function fnKeyDownHandler(getdropdown, e) { fnSanityCheck(getdropdown);
1
3523
by: ksusant | last post by:
Plz help me.. I have 3 combo box in a jsp. I want to display 2nd combo box value with respect to selected 1st combo box value which will be of type onchange and 3rd w.r.t. 2nd selection. And all the values will retrieve from the database. This is my jsp... <html:form action="/nodeAction.do" > <table ><tr><td align="center"><b>NODE DETAILS</b></td> </tr></table>
0
9576
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,...
0
10568
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, 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...
0
10074
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...
0
9138
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5516
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
5647
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4292
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
3813
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2988
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.