Jump to content


Photo

getElementById troubles(solved)


  • Please log in to reply
2 replies to this topic

#1 GingerRobot

GingerRobot
  • Staff Alumni
  • Advanced Member
  • 4,086 posts
  • LocationUK

Posted 06 August 2006 - 03:00 PM

Ok, i have solved my previous problem but have another so i might as well just modify this topic.

why does this:
parent.document.all.due.value=date;
work, and not this:
parent.document.getElementById('due').value=date;

As i understand it, you shouldn't use all anymore, but use getElementById, and certainly Firefox gives a warning although it still functions.

Any help would be much appreciated.

Thanks, Ben

#2 448191

448191
  • Staff Alumni
  • Advanced Member
  • 3,545 posts
  • LocationNetherlands

Posted 07 August 2006 - 08:44 AM

Try to stick to methods and props defined in the DOM level 2 W3C recommendation, and implement fixes for IE.

document.getElementById('due').nodeValue = date;

Should work in at least IE6 and FF, not sure about all versions of IE5.

You might have to use a little object detection.

Some older versions of IE use the "document.all" model, which sucks, but is better than nothing:

if (!document.getElementById) {
       if(!document.all)  {
        //DOM not supported :'(
         return;
        }
             else {
             //Document.all model
             document.all.due.value=date;
        }
}
         else {
        //W3C DOM
        document.getElementById('due').nodeValue = date;
}

FF did partly adopt Microsoft's document.all model for older sites still using it.

#3 GingerRobot

GingerRobot
  • Staff Alumni
  • Advanced Member
  • 4,086 posts
  • LocationUK

Posted 08 August 2006 - 03:41 PM

Thanks for your help although it seems i must have made a typo when trying what i did above, as that is working fine now in both FF and IE6.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users