473,405 Members | 2,379 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,405 software developers and data experts.

problem adding option to select tag using DOM on mozilla

Hello every body,
I was trying to populate a drop down box using ajax/javascript function. My jsp page has a select tag like this
<select name="compSelect" onChange="changeElement();">
</select>
I am trying to populate the drop down box based on database query. I intend to accomplish the task using follow code
componentList=document.getElementById('compSelect' );
var singleOption= new Option(lableValue,indexValue,true,false);
componentList.add(singleOption,null);

When I tested my code on Mozilla firefox it failed to populate the drop down box. Instead of trying the add functionality I also tried to use appendChild like following
componentList.appendChild(singleOption);
This also failed to produce the result. I found an old post on this site regarding this issue but could not follow the discussion. I am pretty new to javascript/ajax and DOM programming. Can anyone please help me out figuring what is wrong? I would really appreciate your kind help. Thanks in advance.
Jul 18 '07 #1
3 2164
Logician
210 100+
<select name="compSelect" onChange="changeElement();">
.
.
componentList=document.getElementById('compSelect' );

Thanks in advance.
I'm sure the Mozilla Error Console is trying to explain that.
If you want to get a reference to an element by its ID, it needs to have an ID.
Jul 18 '07 #2
psybert
10
I'm still a beginner, but this is one that stumped me at first. Add an ID to the <select>!

Expand|Select|Wrap|Line Numbers
  1. <select name="compSelect" id="compSelect" onChange="changeElement();">
  2. </select>
  3.  
Jul 18 '07 #3
Adding Id solved the problem.. Thanks so much for your help.
Jul 18 '07 #4

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

Similar topics

6
by: Andrus | last post by:
I want that if user clicks in a checkbox, the strike-through effect applices to current table row. I tried the following code in IE, but nothing happens. Any idea ? <table> <tr><td><input...
6
by: George Hester | last post by:
Try it. Using Microsoft Internet Explorer 5.5 SP2 (that's the version I am using) in Windows 2000 SP3: In a html put this in: <select type="select-one" id="oSel1"> <option value="1"...
3
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...
6
by: Scott | last post by:
The code below appears to work on the following: MAC - Safari PC - IE PC - Opera But the addition of items to the dropdown (select2) does not function in: MAC – IE
1
by: rlynch99 | last post by:
On of my associates has been having problmes with a postback to self in IE using Localhost... We are trying to figure out why and how to fix it. He has already posted here, but to make sure the...
13
by: Oliver Hauger | last post by:
Hello, In my html form I show a select-element and if this element is clicked I fill it per JavaScript/DOM with option-elements. I use the following code: <!DOCTYPE HTML PUBLIC "-//W3C//DTD...
2
by: kgrenier12 | last post by:
I'm new at using php. I am creating a basic html "contact us" form using php to send the data securely via email. I posted the form and the screen turns blank when I hit the "submit" button. ...
1
by: skyson2ye | last post by:
Hi, guys: I have written a piece of code which utilizes Javascript in PHP to create a three level dynamic list box(Country, States/Province, Market). However, I have encountered a strange problem,...
2
by: swethak | last post by:
Hi, I am getting the problem the problem with google map in Internet Explorer. This map worked fine in mozilla . When i opened the same map in Internet Explorer i am getting the error...
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: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...
0
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,...

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.