document.write problems

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Russell Quinn

    document.write problems

    hi there,

    I am trying to use document.write to write an event handler, but all
    I get is syntax errors..(this is all on one line)

    document.write( '<a href="#" onClick="jkpopi mage("'+imageFi leName+'",
    "'+imageText+'" ); return false"><img src="'+thumbFil eName+'" width="50"
    height="50" border="1"></a>');

    The actual error is the first occurance of >... anyone shed any light on
    this?

    Thanks,

    Russell


  • Michael Winter

    #2
    Re: document.write problems

    Russell Quinn wrote on 24 Nov 2003:
    [color=blue]
    > hi there,
    >
    > I am trying to use document.write to write an event handler, but
    > all I get is syntax errors..(this is all on one line)
    >
    > document.write( '<a href="#"
    > onClick="jkpopi mage("'+imageFi leName+'", "'+imageText+'" );
    > return false"><img src="'+thumbFil eName+'" width="50"
    > height="50" border="1"></a>');
    >
    > The actual error is the first occurance of >... anyone shed any
    > light on this?[/color]

    The more likely error is that you didn't escape the forward slash:

    '...</a>'); should be '...<\/a>');

    Other than that, the statement is fine. The only other possible
    problem would be that the jkpopimage() function isn't defined, but
    you'll have to check that.

    Mike

    --
    Michael Winter
    M.Winter@blueyo nder.co.uk.invalid (remove ".invalid" to reply)

    Comment

    • Lasse Reichstein Nielsen

      #3
      Re: document.write problems

      "Russell Quinn" <russell.quinn@ *PLEASENOSPAM*b lueyonder.co.uk > writes:
      [color=blue]
      > I am trying to use document.write to write an event handler, but all
      > I get is syntax errors..(this is all on one line)[/color]

      When do you get syntax errors? When calling document.write, or when
      calling the event handler?

      What, *exactly*, are the contents of imageFileName and imageText?
      [color=blue]
      > The actual error is the first occurance of >... anyone shed any light on
      > this?[/color]

      What is the error message?
      Which browser do you use?
      (And can we see the rest of the page?)

      /L
      --
      Lasse Reichstein Nielsen - lrn@hotpop.com
      DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html>
      'Faith without judgement merely degrades the spirit divine.'

      Comment

      • VK

        #4
        Re: document.write problems

        Did not use this trick for a while, but I remember some security
        limitations on JavaScript via write() method. In 4th versions it did no
        work (was not forwarded to the script interpreter), that was the time I
        dropped it, I'm wondering about now.


        Comment

        • Graham J

          #5
          Re: document.write problems

          > document.write( '<a href="#" onClick="jkpopi mage("'+imageFi leName+'",[color=blue]
          > "'+imageText+'" ); return false"><img src="'+thumbFil eName+'" width="50"
          > height="50" border="1"></a>');
          >
          > The actual error is the first occurance of >... anyone shed any light on
          > this?[/color]

          I had a play and found that IE6 reported a syntax error on running the
          script but Mozilla and Opera were happy. The location of the error wasn't
          usefully reported. However what IE really seemed to be unhappy about that
          the code actually wrote (with invented contents of the variables)...

          <a href="#" onClick="jkpopi mage("filename. jpg","some text"); return false">

          ....and you can see that the onClick code is delimited by double quotes but
          also has them in the contents. Changing the delimiting quotes to \' made IE
          happy.




          Comment

          • Russell Quinn

            #6
            Re: document.write problems

            [color=blue]
            > ...and you can see that the onClick code is delimited by double quotes but
            > also has them in the contents. Changing the delimiting quotes to \' made IE
            > happy.[/color]

            thanks for all the comments, i eventually worked it out later... it was the above
            suggestion that I had the function parameters delimited by the same method
            as the onClick handler :o(


            Comment

            Working...