This is a discussion on "Function parameters that include quotes" within the JavaScript Forum section. This forum, and the thread "Function parameters that include quotes are both part of the Program Your Website category.
|
|
|
|
|
![]() |
||
Function parameters that include quotes
|
||
| Notices |
![]() |
|
|
LinkBack | Thread Tools |
|
|||
|
Function parameters that include quotes
hi there,
I'm dynamically constructing(PHP) an img element with an onClick event-handler which calls a JavaScript function.
I use the htmlspecialchars php function to change the quotes to their html entities, which i've verified in the page source, but it seems the JS function converts them back to regular characters and then dies upon finding a quote. any help would be greatly appreciated. Last edited by loorp; Sep 15th, 2006 at 08:26. |
|
|
|
||||
|
Re: Function parameters that include quotes
You can escape quotes in both PHP and javascript:
|
|
||||
|
Re: Function parameters that include quotes
Oh, and if you've already tried that, attempt to use double slashes somewhere in there.
|
|
|||
|
Re: Function parameters that include quotes
As you can see from the code, I am already escaping one set of quotes.
at the moment, by using,
Strings containing double quotes still die. if I change it to
The question is how to have a javascript function accept an HTML entity in the parameter and not convert it to it's corresponding character. Here is my JavaScript function call in the resultant HTML page
Quote:
Last edited by loorp; Sep 15th, 2006 at 07:58. |
|
|||
|
Re: Function parameters that include quotes
onClick='changeImg(138, "There's some goin"down", "HOwZ&at");'
Look at the bit I've highlighted. The single quotes are seen as matching and what's between them is taken as your function so the error message is quite right. |
|
|||
|
Re: Function parameters that include quotes
thanks for the reply.
Yes the error message is totally understandable. I would however like to resolve this. I've tried addslahes in PHP to slash out that first ' but then the resulting html test is There\'s some... Is there a "stripslashes" function available in JS? Thanks |
|
|||
|
Re: Function parameters that include quotes
Try this format:
|
![]() |
| Tags |
| function, parameters, include, quotes |
| Thread Tools | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Include PHP in MYSQL Function? | Jack Franklin | PHP Forum | 3 | Mar 24th, 2008 19:35 |
| Problem with displaying random quotes from a function | Z101 | JavaScript Forum | 3 | Dec 7th, 2007 22:34 |
| [SOLVED] Does using PHP include() function affect my SEO ? | RohanShenoy | Search Engine Optimization (SEO) | 3 | Nov 22nd, 2007 18:13 |
| Quotes in strings | jakyra | Classic ASP | 5 | Sep 9th, 2003 15:10 |