Jump to content

escaping quotes in javascript


chronister

Recommended Posts

Hi Folks,

 

I am completely Javascript stupid and hope to find the time to learn someday. I am using a javascript tooltip from dynamic drive. http://dynamicdrive.com/dynamicindex5/dhtmltooltip2.htm

 

I am using this in conjuction with a php script that pulls a joke of the day from a database. I am having trouble with displaying the answers that have a ' or " in them. If I use stripslashes() and addslashes() I end up with the same problem as if I did not use them. Anyone have a suggestion as to how to get around this?

 

If you want to see it in action, go to http://home.happyjoes.net You will notice that today's joke does not popup on hover. That's because the answer is Because he had no "body" to go with !!

 

The code that creates the link and popup for the answer is here.

 

<a href="#" onMouseover="ddrivetip('<?=$answer ?>',400)"; onMouseout="hideddrivetip()" ><?=$question ?></a>

 

Thanks in advance.

 

Nathan Chronister

Link to comment
Share on other sites

I manually went into the db and added the slashes and it still did not work. The real issue is that by the time the javascript grabs it and wants to display I don't want to display the slashes, so I will have the ' or " in the  code that it tries to display thereby breaking the script.

 

I guess if it comes down to it I will just use a different method to display the answer and not use the javascript tooltip popup.

 

Thank you for your answer I appreciate you taking the time to look at my issue.

 

Nathan Chronister

Link to comment
Share on other sites

Well I figured out my problem

 

The particular item I was messing with had a " in it.

 

 

I will have to use mysql_real_escape_string() when I put things in the database, and use a string_replace() to replace all " with '

 

thanks for help folks.

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.