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

Javascript and select box

This script will work only width Firefox browser

<select id='object'>
</select>

document.getElementById(abject).innerHTML= '<option>yehuda'

For some reason the Explorer browser doesn't refer to the options
inside a select box as an innerHTML object

How can I make it work width Epxlorer?

thanking you in advance

May 15 '07 #1
6 4748
On May 15, 10:08 pm, work.Yeh...@gmail.com wrote:
This script will work only width Firefox browser

<select id='object'>
</select>
A select with no options is invalid HTML.

document.getElementById(abject).innerHTML= '<option>yehuda'
I guess you mean:

document.getElementById('object')...

For some reason the Explorer browser doesn't refer to the options
inside a select box as an innerHTML object
innerHTML isn't an object, it's a property of a DOM object/element.

How can I make it work width Epxlorer?
Use:

var select = document.getElementById('object');
select.options[select.options.length] = new Option('yehuda');
You could also use:

var select = document.getElementById('object');
var oOption = document.createElement('option');
oOption.appendChild(document.createTextNode('yehud a'));
select.appendChild(oOption);
--
Rob

May 15 '07 #2
On May 15, 1:08 pm, work.Yeh...@gmail.com wrote:
This script will work only width Firefox browser

<select id='object'>
</select>

document.getElementById(abject).innerHTML= '<option>yehuda'

For some reason the Explorer browser doesn't refer to the options
inside a select box as an innerHTML object

How can I make it work width Epxlorer?

thanking you in advance
you could just insert something a little bit more complete than that

<html><body>
<div id="d"></div>
<script type="text/javascript">
var f = document.getElementById('d');
//next line all one line
f.innerHTML = '<select id="s"><option value="a">a</option><option
value="b">b</option></select>';
</script>
</body>
</html>

instead of creating it invalid and adding to it.

May 15 '07 #3
On May 15, 2:35 pm, RobG <r...@iinet.net.auwrote:
On May 15, 10:08 pm, work.Yeh...@gmail.com wrote:
This script will work only width Firefox browser
<select id='object'>
</select>

A select with no options is invalid HTML.
document.getElementById(abject).innerHTML= '<option>yehuda'

I guess you mean:

document.getElementById('object')...
For some reason the Explorer browser doesn't refer to the options
inside a select box as an innerHTML object

innerHTML isn't an object, it's a property of a DOM object/element.
How can I make it work width Epxlorer?

Use:

var select = document.getElementById('object');
select.options[select.options.length] = new Option('yehuda');

You could also use:

var select = document.getElementById('object');
var oOption = document.createElement('option');
oOption.appendChild(document.createTextNode('yehud a'));
select.appendChild(oOption);

--
Rob
thanks

May 15 '07 #4
ASM
RobG a écrit :
Use:

var select = document.getElementById('object');
select.options[select.options.length] = new Option('yehuda');
// the complete code :
select.options[select.options.length] = new Option('yehuda',
'yehuda's value');

Or ... :

var o = new Option();
o.text = 'yehuda';
o.value = 'yehuda's value';
select.options[select.options.length] = o;

You could also use:

var select = document.getElementById('object');
var oOption = document.createElement('option');
oOption.appendChild(document.createTextNode('yehud a'));
// plus, if a value is needed :
oOption.value = 'yehuda's value';
select.appendChild(oOption);

--
Stephane Moriaux et son (moins) vieux Mac déjà dépassé
Stephane Moriaux and his (less) old Mac already out of date
May 15 '07 #5
I may know your problem.

it is a bug of internet explorer, please see this article:

http://support.microsoft.com/?scid=k...6228&x=11&y=14

May 15 '07 #6
ASM wrote:
RobG a écrit :
>Use:

var select = document.getElementById('object');
select.options[select.options.length] = new Option('yehuda');

// the complete code :
select.options[select.options.length] = new Option('yehuda',
'yehuda's value');

There are four optional arguments:

new Option([text[, value[, defaultSelected[, selected]]]])
--
Rob
We shall not cease from exploration, and the end of all our
exploring will be to arrive where we started and know the
place for the first time. -- T. S. Eliot
May 15 '07 #7

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

Similar topics

13
by: Kai Grossjohann | last post by:
It seems that Ctrl-N in Mozilla opens a new empty browser window. That's fine, I don't need to do anything about it. But Ctrl-N in IE appears to clone the current window. Is there a way to...
1
by: bin_P19 P | last post by:
the code i have got is as follows and now im stuck <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <title>Shopping...
3
by: Richard | last post by:
I have tried to create a javascript puzzle where by the grid is filled with numbers from 1 to 26 and another grid listed 1 to 26 where each number relates to a letter. Once you figure out the...
9
by: beguigne | last post by:
Below is a snippet of a crude date picking routine for a form. I am a novice at this so, I am hitting my head at why when I select the day, the onChange event gives me a blank. What am I missing?...
6
by: Steve B. | last post by:
Hello everybody In a webpage, I use JS display data from an xml file and a xsl file: var data = new ActiveXObject("Microsoft.XMLDOM"); data.async = false; var dataUrl = "data.aspx";...
3
by: bloc | last post by:
I am programming an interactive CV using xml, xslt and java script. The page consists of a header which contains links to various 'sections' on the xml cv, a left and right menu, and a central...
24
by: firstcustomer | last post by:
Hi, Firstly, I know NOTHING about Javascript I'm afraid, so I'm hoping that someone will be able to point me to a ready-made solution to my problem! A friend of mine (honest!) is wanting to...
13
by: monomaniac21 | last post by:
hi i want to be able to trigger a javascript style popup alert in php (i want a message displayed on the actual page) is this possible?
4
by: Adam Smith | last post by:
Hello, How can I call or trigger an external javascript twice in a form? I have <script language="JavaScript" src="country_state.js" name="Country_State"> <script type="text/javascript"...
3
by: Venturini | last post by:
I am trying to put together a web page where the customer makes choices of products and is then given a total. I am extremely new to Javascript and have managed to get as far as I have from web...
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:
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
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...
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:
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
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...
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.