473,385 Members | 1,357 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

spaces.. how to deal with this?



Why doesn't this work? specifically, the space in "word word" throws
it all off. What's the right way to do this? Thanks. -jf

<script language="JavaScript">
function change_text(id,str) {
document.getElementById(id).innerHTML=str
}
</script>

<div onclick=change_text("num1","word word")>click here</div>
Span: <b><span id="num1">num1</span></b>

Jul 23 '05 #1
3 1324
J. Franchino wrote:

Why doesn't this work? specifically, the space in "word word" throws
it all off. What's the right way to do this? Thanks. -jf

<script language="JavaScript">
The language attribute is depreciated, type is required:

<script type="text/javascript">
function change_text(id,str) {
document.getElementById(id).innerHTML=str
}
</script>

<div onclick=change_text("num1","word word")>click here</div>
While HTML element attribute values don't always need quotes, onclick
attribute values nearly always do. It's good practice to always quote
all attribute values.

Change the above to:

<div onclick="change_text('num1','word word');">click here</div>

Note the use of single quotes inside double quotes (you could also use
doubles inside singles...) but nest any deeper and you need to start
quoting quotes with backslash character \.

Be cautious with innerHTML, it is a quick 'n dirty method for replacing
HTML. It's behaviour is not standardised and has some significant
differences on various platforms.

[...]

--
Rob
Jul 23 '05 #2
thx for the tips

Jul 23 '05 #3
ASM
J. Franchino wrote:

Why doesn't this work? specifically, the space in "word word" throws
it all off. What's the right way to do this? Thanks. -jf

<script language="JavaScript">
function change_text(id,str) {
document.getElementById(id).innerHTML=str
}
</script>

<div onclick=change_text("num1","word word")>click here</div>
Span: <b><span id="num1">num1</span></b>


with :

<div onclick="change_text('num1','word word')">click here</div>

it works fine (Mac & FF)

--
Stephane Moriaux et son [moins] vieux Mac
Jul 23 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
by: Magix | last post by:
Hi, Everytime I received a fix-length of string, let say 15 (the unused portion will filled with Spaces before receive), I want to remove the Spaces from END until I encounter a non-space char....
9
by: Durgesh Sharma | last post by:
Hi All, Pleas help me .I am a starter as far as C Language is concerned . How can i Right Trim all the white spaces of a very long (2000 chars) Charecter string ( from the Right Side ) ? or how...
1
by: Anonieko Ramos | last post by:
> > > How to display multiple spaces in a dropdownlist webform1.aspx <asp:DropDownList id="DropDownList1" runat="server"></asp:DropDownList>
7
by: usenet | last post by:
I would like, if it's possible, to set the value of a field in a table to a number of spaces. One space would be fine, I just want to be able to set the field to a default value that's not NULL...
5
by: s99999999s2003 | last post by:
hi i have a dir that contains directories with names and spaces in between example rootdir | ----> ABC DEF A | ---> BDD SD N I wanted to touch a file with the same name as the directories...
135
by: Xah Lee | last post by:
Tabs versus Spaces in Source Code Xah Lee, 2006-05-13 In coding a computer program, there's often the choices of tabs or spaces for code indentation. There is a large amount of confusion about...
40
by: raphfrk | last post by:
I have a program which reads in 3 filenames from the command line prog filename1 filename2 filename3 However, it doesn't work when one of the filenames has spaces in it (due to a directory...
3
by: ayan4u | last post by:
well i need to deal with white spaces in charecter arrays... with static arrays its fine.. char ss; cin.getline(ss, sizeof ss); .... //deals with white spaces
41
by: nospam | last post by:
If I have a string say: myvar = "This is a string"; How do I use sprintf to convert the string so it has 4 spaces padded on the left like:
9
by: jeddiki | last post by:
Hi, I am generating dynamic links and some don't work. Is it because they have a space in the link ? eg: from the name "David Franklyn", I get the link <a href="www.mysite/David...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...

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.