JavaScript Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingJavaScript Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
Free Web 2.0 Code Generator! Generate data entry and reporting .NET Web apps in minutes. Quickly create visually stunning, feature-rich apps that are easy to customize and ready to deploy. Download Now!
  #1  
Old March 17th, 2004, 02:57 PM
buckeye buckeye is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2004
Posts: 1 buckeye User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Who can help escape apostrophe's N Javascript?

I'm using asp.net for my server side lang, and I assign a value to a label. when render the page it comes out like
<span id=something>Somethign from DB in here</span>
My question is the span inner html could very well have 's. This is breaking my JavaScript. I tried to use the replace() but it only replaces the very first ' but not others after it.
example:
function cleanstring(str) {
var mystr
var i
for (i = 0; i <= str.length; i++)
{
mystr = str.replace(/'/,"")
}
return mystr
}
I just want to replace 's with ""

this is what calls the function
function saveLinks(){
var cleanstr = cleanstring(document.getElementById('testing').inn erHTML)
document.write ('<a href="javascript:addCookieArray(\'' + cleanstr + '\',\'' + location.href + '\');">save for later');
}

this totally works with no apostrophes but breaks with more than 2 's.

thanks

Reply With Quote
  #2  
Old March 17th, 2004, 05:48 PM
stumpy's Avatar
stumpy stumpy is offline
May contain nuts.
Dev Articles Regular (2000 - 2499 posts)
 
Join Date: Aug 2002
Location: Sydney, AU
Posts: 2,058 stumpy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 h 6 m 11 sec
Reputation Power: 8
Send a message via ICQ to stumpy Send a message via MSN to stumpy
Replacing ' with " wont work either - CSS rules are not allowed to have any characters other than a-Z, 0-0 in them. Why not use the .net replace function?
__________________
DevArticles Moderator
BlueSix - Web Development and Consulting

Reply With Quote
  #3  
Old July 30th, 2004, 11:13 AM
sirpip sirpip is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Posts: 1 sirpip User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
In JavaScript, to easily do multiple replaces of a character (apostrophes in this case), use the syntax:

mystr = mystr.split("'").join("\'");

Split creates an array of strings from your original seperated by the string parameter passed, and the Join takes that array and recreates the string, adding the string parameter passed between each segment. Another good use for this is with new line characters, where you can Split("\n") and Join("\\n").

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingJavaScript Development > Who can help escape apostrophe's N Javascript?


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway