How can I embed JavaScript function calls in a document.write statement?

Discussion in 'Javascript' started by John, Nov 16, 2004.

  1. John

    John Guest

    Hi,
    I am getting syntax errors in my JavaScript code, code snippet as follows
    (between my <script></script> tags:

    document.write(<a title="Nice to meet you" href="http://www.mydomain.com/"
    onmouseout="MM_swapImgRestore()"
    onmouseover="MM_swapImage(\'welcome\',\'\',\'../images/topnav/welcome_b_mydo
    main-com.gif\',\'meet_the_team\',\'\',' + g_meet_the_team +
    ',\'rave_reviews\',\'\',' + g_rave_reviews +
    ',\'slide_show\',\'\',\'../images/topnav/slide_tour_a_mydomain-com.gif\',\'w
    ho_we_are\',\'\',' +
    ',\'welcome_footer\',\'\',\'../images/topnav/welcome_sub_5_mydomain-com.gif\
    ',1)">');
    document.write(<img src="../images/topnav/welcome_a_mydomain-com.gif"
    width="97" height="24" alt="Nice to meet you" border="0"
    name="welcome"></a></td>');

    I *think* it's because I have function calls (e.g. MM_swapImgRestore())
    within the document.write statement. These calls pertain to my rollover
    functions which are declared prior. Is there a way to do this?

    Thanks,
    Don
    John, Nov 16, 2004
    #1
    1. Advertising

  2. John

    John Guest

    Sorry for multiple posts - Outlook Express went nuts ~
    John, Nov 16, 2004
    #2
    1. Advertising

  3. On Mon, 15 Nov 2004 20:00:41 -0500, John <> wrote:

    [snip]

    You've omitted the opening quote...

    > document.write(<a title="Nice to meet you"


    ....here... ^

    [snip]

    > document.write(<img src="../images/topnav/welcome_a_mydomain-com.gif"


    ....and here. ^

    [snip]

    > name="welcome"></a></td>');


    Those closing tags should be written:

    <\/a><\/td>

    within that string. User agents are allowed to treat </ within a SCRIPT
    element as the closing tag for that element.

    By the way, please don't allow your news reader to automatically wrap
    code. No-one will be able to copy your code and run it as they have to fix
    all of the inserted line breaks. Instead, manually wrap to 80 characters
    at the very most. It's laborious, but it's in your interest.

    [snip]

    Mike

    --
    Michael Winter
    Replace ".invalid" with ".uk" to reply by e-mail.
    Michael Winter, Nov 16, 2004
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Spartanicus
    Replies:
    4
    Views:
    1,353
  2. Replies:
    2
    Views:
    894
    Bengt Richter
    Aug 1, 2005
  3. John
    Replies:
    0
    Views:
    87
  4. Bob
    Replies:
    5
    Views:
    248
  5. Frank Peterson
    Replies:
    9
    Views:
    218
    David Mark
    Jun 28, 2009
Loading...

Share This Page