473,606 Members | 2,409 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Setting "text" value to "option" element in IE

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_count ry=document.cre ateElement("sel ect");
var option;
for(var i=0; i<arr.length; i++){
option=document .createElement( "option");
option.value=ar r[i].code;
option.text=arr[i]._value;
alert(option.va lue+" - "+option.te xt);
this.form_count ry.appendChild( option);
}

It works perfeclty on FireFox, funny thing is that the alert works
properly but there is no way to see any text inside :S

Any idea? Of course I googled and very strangely I didn't find anything
about it.
Many thanks, chr

Nov 23 '05 #1
2 3778
gabon wrote:
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_count ry=document.cre ateElement("sel ect");
I'll use this for convenience, you may chose to do so, or not:

var sel = document.create Element("select ");

var option;
for(var i=0; i<arr.length; i++){
Replace from here...
option=document .createElement( "option");
option.value=ar r[i].code;
option.text=arr[i]._value;
alert(option.va lue+" - "+option.te xt);
this.form_count ry.appendChild( option);
.... to here with:

sel.options[sel.options.len gth] =
new Option(arr[i]._value, arr[i].code);
Change 'sel' back to 'this.form_coun try' if you want.
}

It works perfeclty on FireFox, funny thing is that the alert works
properly but there is no way to see any text inside :S

Any idea? Of course I googled and very strangely I didn't find anything
about it.


Syntax of new Option is:

new Option([text[, value[, defaultSelected[, selected]]]])

where defaultSelected & selected are booleans (true/false).
This is an old reference, but all I could find in a hurry (sleep
beckons...):

<URL:http://devedge-temp.mozilla.or g/library/manuals/2000/javascript/1.3/reference/option.html>

--
Rob
Nov 23 '05 #2
Thanks a lot Rob, it's what I needed :)
Nice one, chr

Nov 23 '05 #3

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

Similar topics

4
2496
by: thomastk | last post by:
Hi, In the following script, I am trying to set selection to a select option element, that is newly created within the script. It works fine on IE installations on Windows 2000 and some XP machines. But on some XP machines, the selection doesn't happen and it defaults to the first element in the options array. Has anybody come across this problem ? Any known workarounds? Thanks Thomas.
2
5653
by: IkBenHet | last post by:
Hello, I am uploading a file using this form in ASP.NET. I have also added a simpel textfield: <form runat="server" enctype="multipart/form-data"> <input type="file" id="oFile" Name="oFile" size="70" runat="Server"> <input type="text" SIZE="20" MAXLENGTH="20" id="Name" NAME="Name"> <input type="submit" id="Submit" runat="Server" value="Submit" OnServerClick="SubmitButton_Click"> </form>
1
3505
by: Linda | last post by:
Hi, Is there a way to do a "text" (rather than "binary") compareison with the "like" operator, without changing the global "Option Compare" setting? I don't want to risk breaking many, many lines of functional code just to get one "like" operation to behave as I wish. I want to check whether a single-character string is (a letter or number, INCLUDING diacritical letters) or whether it is (something else.)
1
3673
by: Brent | last post by:
I thought this would be a problem easily fixed in a simple Google search, but I'm having a hard time finding a solution. I simply need a way to set the value of an option element from an option value provided in an AJAX response. I'm doing just fine with text boxes and div elements, but the option value eludes me. I've tried the following: document.editForm.co_status.selected =...
4
62206
by: millw0rm | last post by:
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(anOption); anOption.innerText = "NewElement"; anOption.Value = "99";
8
5544
by: wecka | last post by:
Does any one know to bound the choices of an option group to a table. Table structure is ID, Text which shall map to Text, Value for the radio buttons repectively. Appreciate advice. - Hany
5
28238
by: balakrishnan.dinesh | last post by:
hi Frnds, I need Confirm box with "yes" or "no" buttons, Is that possible in JAVASCRIPT , Can anyone tell me the solution for this or anyother way to create confirm box with "yes" or "no" button? Thanks & Rgrds Dinesh...
4
2045
by: rebeccatre | last post by:
please help me with this, <style> #a, option.message {background-color: green; color: white;} #b, option.message {background-color: yellow; color: black;} </style> <select id="thisselect"> <option id="thisone" class="message">THANK YOU</option> </select>
6
7124
by: cepera | last post by:
Hi guys! How I can retrieve "option value" info from select tag? I am using this code, but it is only let me get "name". I need to pass this value to second select tag. I found this code here: http://adamv.com/dev/javascript/http_request but they do not have any instructions how to retrieve option values. ----------JS------------
0
8016
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 usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
7955
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,...
1
8096
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 most users, this new feature is actually very convenient. If you want to control the update process,...
0
8306
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
6773
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...
1
5966
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5466
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
3937
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
3980
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.