Jump to content

getElementById troubles(solved)


GingerRobot

Recommended Posts

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
Link to comment
Share on other sites

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

[code]document.getElementById('due').nodeValue = date;[/code]

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

You might have to use a little [url=http://"http://javascriptkit.com/javatutors/objdetect2.shtml"]object detection[/url].

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

[code]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;
}[/code]

FF did partly adopt Microsoft's document.all model for older sites still using it.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.