473,387 Members | 1,574 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.

document.createElement("OPTION") + FireFox

Hi wats wrng with this code??? it works fine on IE6 but not on FireFox
1.5???

var anOption = document.createElement("OPTION");
document.getElementById("category").options.add(an Option);
anOption.innerText = "NewElement";
anOption.Value = "99";

Mar 23 '06 #1
4 62186


mi******@gmail.com wrote:
Hi wats wrng with this code??? it works fine on IE6 but not on FireFox
1.5???

var anOption = document.createElement("OPTION");
document.getElementById("category").options.add(an Option);
The W3C DOM Level 2 HTML defines an add method for the select element object
<http://www.w3.org/TR/DOM-Level-2-HTML/html.html#ID-94282980>
but not for the options collection. However using that method is
difficult as IE implements the method with the same name with different
parameters.
If you simply want to add an option then using the DOM Level 0
var select = document.forms.formName.elements.selectName;
select.options[select.options.length] = new Option('text', 'value');
is much better in terms of browser compatibility.
anOption.innerText = "NewElement";
Firefox does not support the innerText property at all. For option
element objects you can set
anOption.text
anOption.Value = "99";


JavaScript is case sensitive, the property is named value and not Value.
--

Martin Honnen
http://JavaScript.FAQTs.com/
Mar 23 '06 #2
---------------------
var select = document.forms.formName.elements.selectName;
select.options[select.options.length] = new Option('text', 'value');
---------------------
wow, it worked..

after posting i realised the Cap-Letter 'V' => value.. neways my last
question.. how do i deal with this????

anOption.selected = true;
thnx a lot!!!


Martin Honnen wrote:
mi******@gmail.com wrote:
Hi wats wrng with this code??? it works fine on IE6 but not on FireFox
1.5???

var anOption = document.createElement("OPTION");
document.getElementById("category").options.add(an Option);


The W3C DOM Level 2 HTML defines an add method for the select element object
<http://www.w3.org/TR/DOM-Level-2-HTML/html.html#ID-94282980>
but not for the options collection. However using that method is
difficult as IE implements the method with the same name with different
parameters.
If you simply want to add an option then using the DOM Level 0
var select = document.forms.formName.elements.selectName;
select.options[select.options.length] = new Option('text', 'value');
is much better in terms of browser compatibility.
anOption.innerText = "NewElement";


Firefox does not support the innerText property at all. For option
element objects you can set
anOption.text
anOption.Value = "99";


JavaScript is case sensitive, the property is named value and not Value.
--

Martin Honnen
http://JavaScript.FAQTs.com/


Mar 23 '06 #3
new Option('text', 'value', 'TRUE');
solved it!!!!!

thnx
mi******@gmail.com wrote:
---------------------
var select = document.forms.formName.elements.selectName;
select.options[select.options.length] = new Option('text', 'value');
---------------------
wow, it worked..

after posting i realised the Cap-Letter 'V' => value.. neways my last
question.. how do i deal with this????

anOption.selected = true;
thnx a lot!!!


Martin Honnen wrote:
mi******@gmail.com wrote:
Hi wats wrng with this code??? it works fine on IE6 but not on FireFox
1.5???

var anOption = document.createElement("OPTION");
document.getElementById("category").options.add(an Option);


The W3C DOM Level 2 HTML defines an add method for the select element object
<http://www.w3.org/TR/DOM-Level-2-HTML/html.html#ID-94282980>
but not for the options collection. However using that method is
difficult as IE implements the method with the same name with different
parameters.
If you simply want to add an option then using the DOM Level 0
var select = document.forms.formName.elements.selectName;
select.options[select.options.length] = new Option('text', 'value');
is much better in terms of browser compatibility.
anOption.innerText = "NewElement";


Firefox does not support the innerText property at all. For option
element objects you can set
anOption.text
anOption.Value = "99";


JavaScript is case sensitive, the property is named value and not Value.
--

Martin Honnen
http://JavaScript.FAQTs.com/


Mar 23 '06 #4


mi******@gmail.com wrote:
new Option('text', 'value', 'TRUE');
solved it!!!!!


Pass in a boolean there e.g.
new Option('text', 'value', true, true)
where the third argument is for the default selected and the fourth for
the selected value (both which are boolean values).

--

Martin Honnen
http://JavaScript.FAQTs.com/
Mar 23 '06 #5

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

Similar topics

2
by: Dave | last post by:
I have a page which uses JavaScript to create form elements using document.createElement('input'), etc.. Both Firefox and IE have no problem accomplishing this and when the form is submitted all...
2
by: rain_c1 | last post by:
Hi! I have problems with document.createElement() in IE when using TR tags. Please look at the following very short example: ------------snip----------------- <table id="test"></table> ...
2
by: gabon | last post by:
I'm creating a select entirely through JavaScript and very strangely IE doesn't show the text in the option elements. Here part of the code: this.form_country=document.createElement("select");...
6
by: raoul | last post by:
MSIE 6.0 apparently does not support protyping with objects created with document.createElement, while Firefox does. I tested it by typing it into the adress bar, but it also appears to be the...
10
by: webEater | last post by:
Hello, I try the following in Firefox and other modern browsers: window.addEventListener('load', function() { document.title = CSS.getClass('fontSize'); var div = document.createElement('div');...
12
by: ssh | last post by:
function testfn(name) var tbody = document.getElementById('hellospace').getElementsByTagName('tbody'); var row = document.createElement('TR'); var cell1 = document.createElement('TD');...
7
by: r_ahimsa_m | last post by:
Hello, I am learning JavaScript. I have a table on HTML page:                 <table id="announcement_fields" border="0">                 <tbody>                 <tr>...
23
by: vunet | last post by:
It is recommended by some sources I found to create IFrames in IE using document.createElement('<iframe src="#">') instead of document.createElement('iframe'). Why and what browser versions to...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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...
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...

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.