Help on Fixing external js

Discussion in 'JavaScript' started by Lukas, Sep 24, 2006.

  1. #1
    was hoping it wouldn't come to this but I cannot get the ext. javascript to work properly with code inserted exactly as in html. I have done other external js with no problems.

    this one uses some html "AFTER" the heading section. it should work fine but I get an error message at line 19 char 30 - expected " ')' " why here..? it is not the end of the code..?

    ext. js is below --

    _______________________


    document.write('<div class="nav1-container">'
    +' <div class="nav1">'
    +' <ul>'
    +' <li><a href="index.htm"><img border="0" src="img/home.jpg" alt="Back to Home Page" width="48" height="20"></a></li>'
    +' <li><a href="c.htm"><img border="0" src="img/c.jpg" width="76" height="20"></a></li>'
    +' <li><a href="a.htm"><img border="0" src="img/blue.jpg" width="52" height="37"></a></li>'
    +' </ul>'
    +' </div>'
    +' </div>' <<<< --Error Code says PROBLEM is Here ****
    +' <div class="site-name">'
    +' <p class="title"><a href="index.html">LS</a></p>'
    +' <p class="subtitle"><a href="index.html">PR</a></p>'
    +' </div>'
    +' <div class="site-slogan-container">'
    +' <div class="site-slogan">'
    +' <p class="title"></p>'
    +' <p class="subtitle"></p>'
    +' <p class="text">EFG</p>'
    +' <p class="text"><a href="f.htm">ABC</a></p>'
    +' </div>'
    +' </div>')'
    +' <div><img class="img-header" src="./images/people.jpg" alt="" width="770" height="250"/></div>'
    +' <div class="nav2">'
    +' <ul>'
    +' <li><a href="p.htm">P</a></li>'
    +' <li><a href="r.htm">R</a></li>'
    +' <li><a href="s.htm">S</a></li>'
    +' <li><a href="t.htm">T</a></li>'
    +' <li><a href="u.htm">U</a></li>'
    +' </ul>'
    +' </div>');
     
    Lukas, Sep 24, 2006 IP
  2. mpea

    mpea Guest

    Messages:
    272
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    0
    #2
    I found your error (after a little bit of trial and error) its the line that has the

    +' </div>')'

    i think you ment just

    +' </div>

    (well thats one error)
     
    mpea, Sep 24, 2006 IP
  3. mpea

    mpea Guest

    Messages:
    272
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    0
    #3
    yep, testing the following works:

    -------------------
    <html>
    <body>

    <script type="text/javascript">
    document.write('<div class="nav1-container">'
    +' <div class="nav1">'
    +' <ul>'
    +' <li><a href="index.htm"><img border="0" src="img/home.jpg" alt="Back to Home Page" width="48"

    height="20"></a></li>'
    +' <li><a href="c.htm"><img border="0" src="img/c.jpg" width="76" height="20"></a></li>'
    +' <li><a href="a.htm"><img border="0" src="img/blue.jpg" width="52" height="37"></a></li>'
    +' </ul>'
    +' </div>'
    +' </div>'
    +' <div class="site-name">'
    +' <p class="title"><a href="index.html">LS</a></p>'
    +' <p class="subtitle"><a href="index.html">PR</a></p>'
    +' </div>'
    +' <div class="site-slogan-container">'
    +' <div class="site-slogan">'
    +' <p class="title"></p>'
    +' <p class="subtitle"></p>'
    +' <p class="text">EFG</p>'
    +' <p class="text"><a href="f.htm">ABC</a></p>'
    +' </div>'
    +' </div>'
    +' <div><img class="img-header" src="./images/people.jpg" alt="" width="770" height="250"/></div>'
    +' <div class="nav2">'
    +' <ul>'
    +' <li><a href="p.htm">P</a></li>'
    +' <li><a href="r.htm">R</a></li>'
    +' <li><a href="s.htm">S</a></li>'
    +' <li><a href="t.htm">T</a></li>'
    +' <li><a href="u.htm">U</a></li>'
    +' </ul>'
    +' </div>');








    </script>

    </body>
    </html>
     
    mpea, Sep 24, 2006 IP
  4. Lukas

    Lukas Well-Known Member

    Messages:
    1,299
    Likes Received:
    23
    Best Answers:
    0
    Trophy Points:
    130
    #4
    thanks for helping.
    I had already taken out the right bracket in the early div on line 19.

    Actually I tried your code twice.cut ans paste and I still get that same error.

    how can you come up with something different..?
     
    Lukas, Sep 24, 2006 IP
  5. mpea

    mpea Guest

    Messages:
    272
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    0
    #5
    how odd, i did actualy copy and paste ,as you have, and then it didnt work from here!
    but when i went back to the code i tried it, and it did work???? I'll and paste it here again
    ------------------------------------------------
    <html>
    <body>

    <script type="text/javascript">
    document.write('<div class="nav1-container">'
    +' <div class="nav1">'
    +' <ul>'
    +' <li><a href="index.htm"><img border="0" src="img/home.jpg" alt="Back to Home Page" width="48" height="20"></a></li>'
    +' <li><a href="c.htm"><img border="0" src="img/c.jpg" width="76" height="20"></a></li>'
    +' <li><a href="a.htm"><img border="0" src="img/blue.jpg" width="52" height="37"></a></li>'
    +' </ul>'
    +' </div>'
    +' </div>'
    +' <div class="site-name">'
    +' <p class="title"><a href="index.html">LS</a></p>'
    +' <p class="subtitle"><a href="index.html">PR</a></p>'
    +' </div>'
    +' <div class="site-slogan-container">'
    +' <div class="site-slogan">'
    +' <p class="title"></p>'
    +' <p class="subtitle"></p>'
    +' <p class="text">EFG</p>'
    +' <p class="text"><a href="f.htm">ABC</a></p>'
    +' </div>'
    +' </div>'
    +' <div><img class="img-header" src="./images/people.jpg" alt="" width="770" height="250"/></div>'
    +' <div class="nav2">'
    +' <ul>'
    +' <li><a href="p.htm">P</a></li>'
    +' <li><a href="r.htm">R</a></li>'
    +' <li><a href="s.htm">S</a></li>'
    +' <li><a href="t.htm">T</a></li>'
    +' <li><a href="u.htm">U</a></li>'
    +' </ul>'
    +' </div>');








    </script>

    </body>
    </html>

    ----------------
    ok i have coppied and pasted this and it did work... hmm now to spot the difference?
    -oh, and remember to use ctr and refresh, or it may be trying to load the previous version
    -- ah i spotted the other error (or difference in this case) the carridge return after height
    --- those [expected " ')' "] errors are always in the wrong place if you havent closed the brackets, since the compiler has no way of knowing where the bracket should be closed.
     
    mpea, Sep 24, 2006 IP
  6. Lukas

    Lukas Well-Known Member

    Messages:
    1,299
    Likes Received:
    23
    Best Answers:
    0
    Trophy Points:
    130
    #6
    ah haaaa!!! found it...yes your code did work .
    BUT when I plugged in full text and one which has that pesky apostrophe it ruffled up everything.

    Thanks for helping
     
    Lukas, Sep 25, 2006 IP
  7. penagate

    penagate Guest

    Messages:
    277
    Likes Received:
    17
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Oh good god.

    This is why you never never ever ever ever use document.write()!

    Use the DOM methods (createElement, appendChild, et al.) and you will never have to worry about syntactic errors.

    - P
     
    penagate, Sep 27, 2006 IP
  8. Lukas

    Lukas Well-Known Member

    Messages:
    1,299
    Likes Received:
    23
    Best Answers:
    0
    Trophy Points:
    130
    #8
    Please tell me how to do that.
    I am really not that advanced in programming.

    I only know some html, css, js , and copy and paste php..

    The reason I am using the external js is to cut down on html code heading and raise my content.

    What I actually want to do now in this .js or "create element" ( if you could show me, pls use what I have above ) is to put a php image rotator script in the img header area..
    I have the php script ready for that, but when I inserted it in the external js, it gave me an error ( syntax ) I did exactly what the php istructions said to do.

    any help is appreciated.

    :(
     
    Lukas, Sep 28, 2006 IP
  9. penagate

    penagate Guest

    Messages:
    277
    Likes Received:
    17
    Best Answers:
    0
    Trophy Points:
    0
    #9
    Hi!

    What exactly do you mean by "cut down on html code heading and raise my content"? Are you trying to shift document structure into scripting? That will never work; what happens if a user without Javascript capability navigates to your page? What do they see?

    Ad rotator scripts shouldn't require JS either - the rotation logic should all be done server-side.

    As for DOM scripting, I suggest you start here:
    http://w3schools.com/dom/

    If you have any queries about any part of that don't hesitate to ask.

    Regards
    - P
     
    penagate, Sep 28, 2006 IP