Page 1 of 2 12 LastLast
Results 1 to 10 of 12

Thread: script error: object required

  1. #1
    Join Date
    Apr 2005
    Location
    Sydney, Australia
    Posts
    49
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Arrow script error: object required

    tnis the script in the head of my HTML doc.
    it says that an object is required at line 4, char 5.
    I thought it was an object?

    Code:
    <script type="text/javascript"><!--
      var d = document;
      function  resizeBox(){
        sObj = d.getElementById("container").style
        if(d.body.clientWidth)(d.body.clientWidth>600) ? sObj.width= "600px" :  sObj.width = "100%" 
      }
       onload = resizeBox;
      onresize = resizeBox;
      //-->
    	</script>
    The script is trying to do that max-width in IE thingy.

    thanx
    WishIwasAgeek

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    29,076
    Thanks
    44
    Thanked 3,216 Times in 3,178 Posts
    Blog Entries
    12

    Default

    If there is no element with the id 'container' (spelling counts!) parsed by the browser at the time this script is executed, there is no object. Also, can you be sure which line is line 4? If it is the 5th line in the snippet (1st line could be 0) and you are using a doctype, document.body is not valid. Also, to be safe, use a line-break after the if statement. That's just off the top of my head, there could be other possibilities.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  3. #3
    Join Date
    Apr 2005
    Location
    Sydney, Australia
    Posts
    49
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    sure - re. line numbers but this is the line identified in HTML-KIT (it was actually line 20 on the error message which made sense in HTML-KIT) but fine.

    What about the container thingy? Didn't I spell it right? What should it say?

    Sorry I don't understand what you are saying re. doctype? are you saying that this script have html rather than body in the above script?

    if not what type of declaration should I be using?

    thanx again
    WIWAG

  4. #4
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    29,076
    Thanks
    44
    Thanked 3,216 Times in 3,178 Posts
    Blog Entries
    12

    Default

    Quote Originally Posted by wishiwasageek
    Code:
    sObj = d.getElementById("container").style
    The above requires an element having the attribute id="container". Ex:
    HTML Code:
    <div id="container">
    
    some stuff can go here
    
    </div>
    The word 'container' must be spelled exactly the same, case sensitive, in both the script and html code. In addition, said element must have been parsed by the browser before the code is executed.

    About doctype - A doctype looks something like this:
    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    and (if used) is the very first thing on a page. Most doctypes invalidate IE's use of 'document.body', requiring instead the more standard 'document.documentElement' however, since some older versions of IE don't recognize doctypes, simply changing to documentElement will mess things up on them, that is another discussion. I'm not familiar with HTML-KIT but, it may assume a doctype even if none is specified.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  5. #5
    Join Date
    Apr 2005
    Location
    Sydney, Australia
    Posts
    49
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    So should the text be changed to document.documentbody?
    (No one is using earlier than IE 6.0)

    thanx
    WIWAG

  6. #6
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    29,076
    Thanks
    44
    Thanked 3,216 Times in 3,178 Posts
    Blog Entries
    12

    Default

    That's document.documentElement (literally) and, how should I know? You have to identify wether or not this is even the problem first. If you ask a question about an isolated piece of code like that, unless there are obvious errors, all you will get will be speculation. I'm getting the feeling that you are looking for a magic bullet fix for the error. In my first response I mentioned several possibilities, all of which should be tried individually and in combination to see if any or all resolve the error. I'm also getting the impression, from your response, that you may be having difficulty holding more than one idea at once in mind while considering this issue. No way to be sure. If that is the case, it will be difficult to advise you further in this manner. Better to put a test page up where I can have a look at it.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  7. #7
    Join Date
    Dec 2004
    Location
    UK
    Posts
    2,358
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    When I covered this a while ago, there seems to have been a few misconceptions on my part, coupled with a little misreading of Microsoft's documentation.

    The simple solution to this problem is to add this to your style sheet:

    Code:
    * html #container {
      width: expression((document.body.clientWidth > 600) ? '600px' : 'auto');
    }
    This works because by the time IE tries to apply the style to the container, it will have encountered the body element so it can read its values. This is why the documentElement property must be used if the style is being applied to the body element itself: only the html element will be accessible when the style sheet is applied.

    As for the newfound ability to use strings and even concatenate them? I have no idea whatsoever as to why it didn't work when I was trying this previously.

    With a bit of jiggery-pokery, it would also be possible to make your comparisons in terms of em units, but that's too much hassle for me at the moment. I have a headache.

    Mike

  8. #8
    Join Date
    Apr 2005
    Location
    Sydney, Australia
    Posts
    49
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    jscheuer1 said
    That's document.documentElement (literally) and, how should I know? You have to identify wether or not this is even the problem first.
    Well if your read mwinter's reply clearly this IS part of the problem.
    How should you jscheuer1 know? well I don't know so how can I tell you?? You don't HAVE to reply!! I appreciate that you do however. Yes, I definitely have trouble with scripting as I am a beginner (hence student tag under my name) but you don't have to get exasperated (or maybe you do! that's cool I'm pretty frustrated too.)

    Sorry to give Mwinter a headache and make you grumpy but I am a beginner and do appreciate your answers always. I could give up and just keep creating crap that works, but am trying to do the right thing here and learn to code things properly.

    jscheuer1 said
    If you ask a question about an isolated piece of code like that, unless there are obvious errors, all you will get will be speculation.
    As to isolated - that's all the code there is - sorry!! I explained what it was trying to do (max width for page)

    Quite seriously - how would you have asked the question that would have been more helpful? I don't want to put a page up as I don't have all the security you guys do like preventing browsing on a directory etc. (and all other guests here). Sorry Jscheuer1 - it's part of being a legendary teacher - you get exasperating students.

    WIWAG

  9. #9
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    29,076
    Thanks
    44
    Thanked 3,216 Times in 3,178 Posts
    Blog Entries
    12

    Default

    Now I'm having trouble following you. If that's all you have, then there is no object, you need an element with the id used by the script or else there is no object, as I said near the start.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  10. #10
    Join Date
    Apr 2005
    Location
    Sydney, Australia
    Posts
    49
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Going to give Mwinter's idea a go first as that seems the simplest.

    Believe it or not I'm with you now - yes there would be an element with an id container in the HTML code I was just asking if there was anything glaringly obvious with the code itself before I even began to apply it to the HTML. If there isn't an element with ID code, then yeah the js wouldn't be happy.

    Like I said, I'll try Mwinter's idea, but thanx for helping me understand the jscript, again it's frustrating for you, but also for me as I can't word my questions properly! I don't know enough about what I'm doing to ask the questions so you understand them. Sorry sorry sorry

    WIWAG

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •