palak1
@gmail.com wrote:
> 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.