Javascript and select box

W

work.Yehuda

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
 
R

RobG

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('yehuda'));
select.appendChild(oOption);
 
S

shimmyshack

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.
 
W

work.Yehuda

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('yehuda'));
select.appendChild(oOption);

thanks
 
A

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('yehuda'));

// plus, if a value is needed :
oOption.value = 'yehuda's value';
 
R

RobG

ASM said:
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]]]])
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,161
Messages
2,570,892
Members
47,427
Latest member
HildredDic

Latest Threads

Top