Connecting Tech Pros Worldwide Forums | Help | Site Map

Java Script and Double Quotes

Newbie
 
Join Date: Oct 2007
Posts: 4
#1: Oct 16 '07
Dear Forum,

First, thanks for reading my Post. So basically I have a Java Script program. To add more to the Data base I can not use " Double Quotes inside the string. How do I work around this irritant and where to I locate the fix. I have done some research about quote blocker script and the use of /" /". But where to exactly place the fix I am unsure..


Thanks, Louis





Thanks, Louis

pbmods's Avatar
Site Moderator
 
Join Date: Apr 2007
Location: Texas
Posts: 5,435
#2: Oct 16 '07

re: Java Script and Double Quotes


Heya, Louis. Welcome to TSDN!

I'm going to go ahead and move this thread to the JavaScript forum, where our resident Experts will be better able to help you out.
acoder's Avatar
Site Moderator
 
Join Date: Nov 2006
Location: UK
Posts: 14,581
#3: Oct 16 '07

re: Java Script and Double Quotes


Can you show some code which demonstrates the problem?

If the double quotes are within double quotes, you'll need to escape them:
Expand|Select|Wrap|Line Numbers
  1. "a double quote \" "
Newbie
 
Join Date: Oct 2007
Posts: 4
#4: Oct 16 '07

re: Java Script and Double Quotes


Quote:

Originally Posted by acoder

Can you show some code which demonstrates the problem?

If the double quotes are within double quotes, you'll need to escape them:

Expand|Select|Wrap|Line Numbers
  1. "a double quote \" "





Expand|Select|Wrap|Line Numbers
  1. <script language="javascript"> <!--
  2. //          ligHTCC's Joke Generator  
  3. // copy as you like. But please try to find
  4. // some better jokes (or quotes, or ???'s)
  5. //
  6. //NOTE: each joke is one long string of words with no 
  7. //      linefeeds and enclosed in "-s (There may be no "-s 
  8. //      inside the string)
  9.  

Explain: Would I do the command above only once or each time..?
Would you explain where this would go in the script?


Thanks a lot , Louis
acoder's Avatar
Site Moderator
 
Join Date: Nov 2006
Location: UK
Posts: 14,581
#5: Oct 16 '07

re: Java Script and Double Quotes


Can you show more of the code? For example, some strings and how they are used in the code?
Newbie
 
Join Date: Oct 2007
Posts: 4
#6: Oct 16 '07

re: Java Script and Double Quotes


Expand|Select|Wrap|Line Numbers
  1. ligHTCC21="My girlfriend told me I should be more affectionate. So I got a second girlfriend.";
  2.  
  3.  
  4. nrOfLines = 69; // total number of jokes.
  5.  
  6. nr = Math.round(0.5+(Math.random()*nrOfLines));
  7.  
  8. self.document.write(eval('ligHTCC'+nr));
  9.  
  10. function dummy() {};
  11.  
  12. function reload() {};
  13.  
  14. // --> </script>
acoder's Avatar
Site Moderator
 
Join Date: Nov 2006
Location: UK
Posts: 14,581
#7: Oct 16 '07

re: Java Script and Double Quotes


Please use code tags when posting code:
[CODE=javascript]
Your JavaScript code here..
[/code]

As an example, see this:
Expand|Select|Wrap|Line Numbers
  1. "My \"girlfriend\" told me..."
Wherever you need to use double quotes within double quotes, escape them in this manner. Alternatively, use single within double and vice versa.
Newbie
 
Join Date: Oct 2007
Posts: 4
#8: Oct 17 '07

re: Java Script and Double Quotes


acoder,



Thanks..... I appreciate it very much. !!!



Louis
acoder's Avatar
Site Moderator
 
Join Date: Nov 2006
Location: UK
Posts: 14,581
#9: Oct 17 '07

re: Java Script and Double Quotes


No problem, you're welcome.
Reply