Home     |     .Net Programming    |     cSharp Home    |     Sql Server Home    |     Javascript / Client Side Development     |     Ajax Programming

Ruby on Rails Development     |     Perl Programming     |     C Programming Language     |     C++ Programming     |     IT Jobs

Python Programming Language     |     Laptop Suggestions?    |     TCL Scripting     |     Fortran Programming     |     Scheme Programming Language


 
 
Cervo Technologies
The Right Source to Outsource

MS Dynamics CRM 3.0

Javascript / Client Side Development

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

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

--
Rob

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.

On May 15, 2:35 pm, RobG <r@iinet.net.au> wrote:

thanks
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';

>   select.appendChild(oOption);

--
Stephane Moriaux et son (moins) vieux Mac dj dpass
Stephane Moriaux and his (less) old Mac already out of date
I may know your problem.

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

http://support.microsoft.com/?scid=kb%3Ben-us%3B276228&x=11&y=14

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

Add to del.icio.us | Digg this | Stumble it | Powered by Megasolutions Inc