javascript function calling problem in php code

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
habib009pk
Forum Commoner
Posts: 43
Joined: Sun Jul 05, 2009 11:28 pm

javascript function calling problem in php code

Post by habib009pk »

Hi Friends,

I am facing a little problem, i am using an ajax function for displaying of images on webpage in php script i wrote that code:

$value2.="<img id='imgBamburgh3' alt='' src='".$pieces[1]."' class='PopBoxImageSmall' title='Click to magnify/shrink' onclick='Pop(this,50,'PopBoxImageLarge')' width='160' height='100' border='0' style='padding:2px;' />";

which makes a string and return the response, it is working good but the problem is that when i click on that image i.e Pop function of javascript has been triggered which magnify that image. this function doesn't work, before that when i pasted that code on my original webpages without ajax it is working properly.

Is it any modification need for that string or syntax error

Kindly Help me

Regards
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: javascript function calling problem in php code

Post by requinix »

Don't see how it worked before. Assuming that you used the same HTML as you have in that PHP code, that is.

Code: Select all

onclick='Pop(this,50,'PopBoxImageLarge')'
The apostrophes conflict. The onclick code is

Code: Select all

Pop(this,50,
bubblesnout
Forum Newbie
Posts: 8
Joined: Thu Sep 10, 2009 5:46 pm

Re: javascript function calling problem in php code

Post by bubblesnout »

Exactly. To clarify, if you change your code to this, you should be fine:

Code: Select all

$value2.="<img id='imgBamburgh3' alt='' src='".$pieces[1]."' class='PopBoxImageSmall' title='Click to magnify/shrink' onclick=\"Pop(this,50,'PopBoxImageLarge')\" width='160' height='100' border='0' style='padding:2px;' />";
What I've done is surround the onclick attribute in double quotes, but escaped them with a slash so PHP doesn't treat them as the end of the string.
habib009pk
Forum Commoner
Posts: 43
Joined: Sun Jul 05, 2009 11:28 pm

Re: javascript function calling problem in php code

Post by habib009pk »

Thank alot, it is working good
Post Reply