473,545 Members | 2,772 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

document.create Element("OPTION ") + FireFox

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

var anOption = document.create Element("OPTION ");
document.getEle mentById("categ ory").options.a dd(anOption);
anOption.innerT ext = "NewElement ";
anOption.Value = "99";

Mar 23 '06 #1
4 62200


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

var anOption = document.create Element("OPTION ");
document.getEle mentById("categ ory").options.a dd(anOption);
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.elemen ts.selectName;
select.options[select.options. length] = new Option('text', 'value');
is much better in terms of browser compatibility.
anOption.innerT ext = "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.elemen ts.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.select ed = 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.create Element("OPTION ");
document.getEle mentById("categ ory").options.a dd(anOption);


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.elemen ts.selectName;
select.options[select.options. length] = new Option('text', 'value');
is much better in terms of browser compatibility.
anOption.innerT ext = "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.elemen ts.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.select ed = 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.create Element("OPTION ");
document.getEle mentById("categ ory").options.a dd(anOption);


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.elemen ts.selectName;
select.options[select.options. length] = new Option('text', 'value');
is much better in terms of browser compatibility.
anOption.innerT ext = "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
2661
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 the information is passed correctly. I am now trying to validate the form using JavaScript when the page is submitted. Firefox has no problems with...
2
1871
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> <script type="text/javascript"> var MyTable = document.getElementById("test");
2
3773
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"); var option; for(var i=0; i<arr.length; i++){ option=document.createElement("option"); option.value=arr.code;
6
1786
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 case for code embedded in a HTML document. Here's a simple segment of code to demonstrate the difference: javascript: function...
10
4247
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'); document.getElementsByTagName('body').appendChild(div); alert(div); alert(div.style) }, true);
12
40124
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'); cell1.align="left"; cell1.style.height = "22"; cell1.style.width = "15"; cell1.valign = "middle"; cell1.className = "dwInfo"; var inp1 =...
7
1821
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>                 <td><span class="obligatory">Offer type</span>:</td>                 <td>                         <select...
23
6556
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 use it? IE5 or IE6? Thanks
0
7502
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, 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...
0
7434
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...
0
7692
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. ...
1
7457
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7791
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...
0
6026
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...
1
1921
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
1
1045
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
744
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...

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.