Connecting Tech Pros Worldwide Help | Site Map

Javascript and select box

  #1  
Old May 15th, 2007, 01:15 PM
work.Yehuda@gmail.com
Guest
 
Posts: n/a
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, 01:35 PM
RobG
Guest
 
Posts: n/a

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, 02:05 PM
shimmyshack
Guest
 
Posts: n/a

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, 02:05 PM
work.Yehuda@gmail.com
Guest
 
Posts: n/a

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, 02:15 PM
ASM
Guest
 
Posts: n/a

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, 02:55 PM
=?gb2312?B?zrrW0Luq?=
Guest
 
Posts: n/a

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, 03:25 PM
RobG
Guest
 
Posts: n/a

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
Closed Thread


Similar Threads
Thread Thread Starter Forum Replies Last Post
Multiple select box, pop up question bonneylake answers 25 September 5th, 2008 02:53 PM
Javascript select box ramya2611 answers 1 January 9th, 2008 12:08 PM
Javascript : Select Box not functioning properly wsharad answers 2 June 13th, 2007 04:19 AM
select of select box will select multiple in another box palmiere answers 1 July 20th, 2005 03:23 PM
PHP and SELECT Box issues JT answers 1 July 17th, 2005 02:36 AM