whitespace in onclick event

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Tarantulus
    New Member
    • May 2007
    • 114

    whitespace in onclick event

    Hi all,

    I have an "onclick" event like so:

    Code:
    <span onclick="getElementById('container').value='foo'>foo</span>
    which works, however if I replace "foo" with "foo bar" it fails

    Code:
    <span onclick="getElementById('container').value='foo bar'>foo bar</span>
    I'm assuming it's due to the whitespace, is there a way to escape it that I'm not aware of?

    Thanks in advance
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    Not sure how the first one worked. It should be document.getEle mentById().

    Comment

    • Tarantulus
      New Member
      • May 2007
      • 114

      #3
      odd, it works fine without "document".

      I've added that it anyway and it still fails, I tried 'foo'+' '+'bar' as well, and that sort of worked but only returned 'foo'

      Comment

      • acoder
        Recognized Expert MVP
        • Nov 2006
        • 16032

        #4
        You've forgotten to close the double quote of the onclick.

        Comment

        • Tarantulus
          New Member
          • May 2007
          • 114

          #5
          Originally posted by acoder
          You've forgotten to close the double quote of the onclick.
          spotted and rectified, thanks!

          Comment

          • acoder
            Recognized Expert MVP
            • Nov 2006
            • 16032

            #6
            I'm not sure how it worked at all to be honest. Anyway, glad it's now working.

            Comment

            • gits
              Recognized Expert Moderator Expert
              • May 2007
              • 5390

              #7
              unless the getElementById( ) method is declared globally or somehow published to the window by an included script/lib or something like that ... i'm also wondering how this could work?

              kind regards

              Comment

              • Tarantulus
                New Member
                • May 2007
                • 114

                #8
                I don't know, but it does! :)

                Comment

                • gits
                  Recognized Expert Moderator Expert
                  • May 2007
                  • 5390

                  #9
                  do you use any included library/script in your code? i think that is the only possible explaination for that ... so it is a 'custom' function in your app that just calls document.getEle mentById() ...

                  kind regards

                  Comment

                  • acoder
                    Recognized Expert MVP
                    • Nov 2006
                    • 16032

                    #10
                    Interesting. I just tested on FF3 and it does work! May have something to do with quirks mode possibly. However, I'm still not sure how it worked without the missing quote.

                    Comment

                    Working...