/    Sign up×
Community /Pin to ProfileBookmark

Problem with a function string parameter that has double quotes

Hi everyone.
First of all, I think this is a javascript issue, but I don’t know if this is a php or html problem, so feel free to guide me through this.

I have a page that opens a secondary window using javascript, let’s say: secondary.php which is a select window.
In that secondary.php I declared the following function:

[CODE]function doPostBack (code,description){
opener.document.form1.txtCode.value=code;
opener.document.form1.txtDescription.value=description;
window.close(this);
}[/CODE]

To populate secondary.php I do the following for each record: (ommiting some lines of php code not necessary for this post)

[CODE]<?
echo “<a href=”javascript:doPostBack(‘$i[0]’,’$i[1]’)”>”;
?>[/CODE]

(where $i is the variable containing the records)

The problem is that there are descriptions containing double quotes, for instance:
code=F001
description=3.5″ floppy disk
Then, the href indicated above must be:
javascript:doPostBack(‘F001′,’3.5″ floppy disk’)
or
javascript:doPostBack(‘F001′,’3.5″ floppy disk’)

but ? the href appears like this:
javascript:doPostBack(‘F001’,’3.5
Note that the last single quote and the ending parenthesis disappeared, so, when I click that href nothing happens.

I’ve tried a lot for days using the php str_replace function

[CODE]str_replace(“””,”\””,$i[0])[/CODE]

but the same thing happens. Now, I’m stuck and that’s why I come here because my brain is destroyed and I don’t know how to go from here.

Did someone here had the same situation?
or
How can I do considering that I can’t change the descriptions on the database?

Can I post this question in php forum? Is it considered as spam?

I really appreciate your help
Thanks

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@A1ien51Feb 16.2006 — i think it needs to be instead of in you replace line

Eric
Copy linkTweet thisAlerts:
@rolandpishauthorFeb 16.2006 — Thanks Eric, I tried with instead of and it didn't work.

Someone told me few minutes ago that the problem is with the html href tag, because when the href tag receives the second double quote, html understands that it is the end of the declaration of the URL href tag, and of course it misses the rest of the parameter. This results in a bad URL declaration, so the call to javascript doPostBack function never happens. That's why it is not a javascript problem. (Now I feel dumb)

He told me to put & #34; as the replace string in the str_replace php function because that is the html escape character for the double quote and voila! it worked.

I hope this post helps all those with the same situation as mine.

Thanks for your reply Eric!

Regards
Copy linkTweet thisAlerts:
@A1ien51Feb 16.2006 — Man, I was not paying attention to that it was in a html tag. I was thinking it was a js variable! Big duh on my part....lol

Eric
×

Success!

Help @rolandpish spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.16,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...