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

document.getElementById issue in Firefox


Hi All,

I am using a javascript to submit a request using AJAX. Part of
javascript code as follows:

var favElement = document.getElementById('fav1');
alert(favElement);
for (var i = 0; i < userGroupArray.length; i++){
      for (var j = 0; j < favElement.length; j++){
         if(favElement.options[j].value == userGroupArray[i]){
             favElement.options[j].selected = true;
         }
       }

}

fav1 is a html select element with attribute multiple="true" (please
see snipet below)

 <select class="" multiple size="4" name="fav1">
        <option value="">-- select --</option>
        <option value='10' >1100</option>
        .....
</select>

In IE 6.0, alert(favElement) returns object properly and rest of the
code works fine...

In FireFox 1.5, alert(favElement) returns null...

In Netscape 7.0 , alert(favElement) does nothing

So the code is failing in Firefox and Netscape. Can anybody suggest,
whats wrong? document.getElementById does not work in Firefox/
Netscape?

Thanks in advance,
Palak

Hi Palak,

I think you confuse name="" and id="".
The name="" is used to create name-value pairs for the receiving script, the
id="" is used to, well, create an id.
So just add id="fav1" and your code is correct.

Regards,
Erwin Moller

Thanks Erwin... issue is resolved... oh that was bad. I did not
realize the mistake.....

Thanks once again....

palak1@gmail.com wrote:

[snip]
>  <select class="" multiple size="4" name="fav1">
>    <option value="">-- select --</option>
>    <option value='10' >1100</option>
>    .....
> </select>

> In IE 6.0, alert(favElement) returns object properly and rest of the
> code works fine...

And that is MSIE doing it wrong because, as you can see, you do not
have an element with the ID "fav1".

> In FireFox 1.5, alert(favElement) returns null...

And that is Firefox doing it *right* (it is not failing, the Microsoft
browser is). There is all the world of difference between a *name* and
an ID. If you look for an ID, you have to have one.
Add to del.icio.us | Digg this | Stumble it | Powered by Megasolutions Inc