473,472 Members | 2,241 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

whitespace in onclick event

Tarantulus
114 New Member
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
9 2106
acoder
16,027 Recognized Expert Moderator MVP
Not sure how the first one worked. It should be document.getElementById().
Oct 30 '08 #2
Tarantulus
114 New Member
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
16,027 Recognized Expert Moderator MVP
You've forgotten to close the double quote of the onclick.
Oct 30 '08 #4
Tarantulus
114 New Member
You've forgotten to close the double quote of the onclick.
spotted and rectified, thanks!
Oct 30 '08 #5
acoder
16,027 Recognized Expert Moderator MVP
I'm not sure how it worked at all to be honest. Anyway, glad it's now working.
Oct 30 '08 #6
gits
5,390 Recognized Expert Moderator Expert
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
114 New Member
I don't know, but it does! :)
Oct 31 '08 #8
gits
5,390 Recognized Expert Moderator Expert
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
16,027 Recognized Expert Moderator MVP
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

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

Similar topics

2
by: josh.asbury | last post by:
I am having some major issues with whitespace in my XSL stylesheets. We recently upgraded our servlet-based application to JDK 1.4, and this has forced the issue of my finally upgrading to...
2
by: RobG | last post by:
I am trying to dynamically add an onclick to an element, however I just can't get the syntax right. consider the following function: function doClick (evt,x) { // do things with evt and x } ...
17
by: abs | last post by:
My element: <span onclick="alert('test')" id="mySpan">test</span> Let's say that I don't know what is in this span's onclick event. Is it possible to add another action to this element's onclick...
6
by: Cockroach | last post by:
Hello, I have a problem where the onClick of a table row will activates a window.location event, and inside a cell in that row, an image onClick event shows/hides a div. The problem is that...
3
by: o_swas | last post by:
Hello, I have a JavaScript string. I want to replace all consecutive occurrences of whitespace characters like spaces, tabs, newlines, and form feeds with another string. For example, say I...
4
by: RobG | last post by:
I have a function whose parameter is a reference the element that called it: function someFunction(el) { ... } The function is assigned to the onclick event of some elements in the HTML...
5
by: kai | last post by:
Hi, In ASP.NET , what is the difference between OnClick and Click events for a button? Because we have button click event, it can trigger events, why we still need OnClick? Please help. ...
7
by: extremerep | last post by:
My task is to change the value of a button and then make it functional with the onClick handler. Changing the value to "Play Again" works, but making the onClick work accordingly does not. The...
9
by: martymix | last post by:
simple question: I have a simple <dt>test text</dt> I get the innerHTML of that dt, and I try and append some text to it like so: dt = document.getElementsByTagName('dt') var text =...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.