Connecting Tech Pros Worldwide Help | Site Map

Javascript and select box

 
LinkBack Thread Tools Search this Thread
  #1  
Old May 15th, 2007, 12:15 PM
work.Yehuda@gmail.com
Guest
 
Posts: n/a
Default 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


  #2  
Old May 15th, 2007, 12:35 PM
RobG
Guest
 
Posts: n/a
Default Re: Javascript and select box

On May 15, 10:08 pm, work.Yeh...@gmail.com wrote:
Quote:
This script will work only width Firefox browser
>
<select id='object'>
</select>
A select with no options is invalid HTML.

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

document.getElementById('object')...

Quote:
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.

Quote:
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

  #3  
Old May 15th, 2007, 01:05 PM
shimmyshack
Guest
 
Posts: n/a
Default Re: Javascript and select box

On May 15, 1:08 pm, work.Yeh...@gmail.com wrote:
Quote:
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.

  #4  
Old May 15th, 2007, 01:05 PM
work.Yehuda@gmail.com
Guest
 
Posts: n/a
Default Re: Javascript and select box

On May 15, 2:35 pm, RobG <r...@iinet.net.auwrote:
Quote:
On May 15, 10:08 pm, work.Yeh...@gmail.com wrote:
>
Quote:
This script will work only width Firefox browser
>
Quote:
<select id='object'>
</select>
>
A select with no options is invalid HTML.
>
Quote:
document.getElementById(abject).innerHTML= '<option>yehuda'
>
I guess you mean:
>
document.getElementById('object')...
>
Quote:
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.
>
Quote:
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

  #5  
Old May 15th, 2007, 01:15 PM
ASM
Guest
 
Posts: n/a
Default Re: Javascript and select box

RobG a écrit :
Quote:
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;

Quote:
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';
Quote:
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
  #6  
Old May 15th, 2007, 01:55 PM
=?gb2312?B?zrrW0Luq?=
Guest
 
Posts: n/a
Default Re: Javascript and select box

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

  #7  
Old May 15th, 2007, 02:25 PM
RobG
Guest
 
Posts: n/a
Default Re: Javascript and select box

ASM wrote:
Quote:
RobG a écrit :
Quote:
>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
 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,989 network members.