By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,851 Members | 1,095 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,851 IT Pros & Developers. It's quick & easy.

whitespace in onclick event

Tarantulus
100+
P: 114
Hi all,

I have an "onclick" event like so:

Expand|Select|Wrap|Line Numbers
  1. <span onclick="getElementById('container').value='foo'>foo</span>
which works, however if I replace "foo" with "foo bar" it fails

Expand|Select|Wrap|Line Numbers
  1. <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
Oct 30 '08 #1
Share this Question
Share on Google+
9 Replies


acoder
Expert Mod 15k+
P: 16,027
Not sure how the first one worked. It should be document.getElementById().
Oct 30 '08 #2

Tarantulus
100+
P: 114
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'
Oct 30 '08 #3

acoder
Expert Mod 15k+
P: 16,027
You've forgotten to close the double quote of the onclick.
Oct 30 '08 #4

Tarantulus
100+
P: 114
You've forgotten to close the double quote of the onclick.
spotted and rectified, thanks!
Oct 30 '08 #5

acoder
Expert Mod 15k+
P: 16,027
I'm not sure how it worked at all to be honest. Anyway, glad it's now working.
Oct 30 '08 #6

gits
Expert Mod 5K+
P: 5,235
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
Oct 30 '08 #7

Tarantulus
100+
P: 114
I don't know, but it does! :)
Oct 31 '08 #8

gits
Expert Mod 5K+
P: 5,235
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.getElementById() ...

kind regards
Oct 31 '08 #9

acoder
Expert Mod 15k+
P: 16,027
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.
Oct 31 '08 #10

Post your reply

Sign in to post your reply or Sign up for a free account.