Page 1 of 1

Javascript inside PHP code

Posted: Fri Mar 11, 2011 1:25 pm
by ms.Jemi
Hi guyz...
I need some with my php code.
I want to have a pop window in my a href link inside the php code.
But I have problems coz there is an error regarding with my script inside the php
Here is my code

echo "<td><img src=".$img[$x]." width='250' height='250'><br>".'<input type="checkbox" name="formVotes[]" value="'.$canId[$x].'" /><br>'.$fName[$x]."&nbsp;".$mName[$x]."&nbsp;".$lName[$x]."&nbsp;".'</input><br> <a href="viewprofile.php?canid='.$canId[$x].'" target="popupWin" onsubmit="return openWindow('addProfile.php', 'popupWin', 1000, 500);">View Profile</a></td>';

I really need your help guyz...
Thank you in advance!

Re: Javascript inside PHP code

Posted: Fri Mar 11, 2011 3:54 pm
by social_experiment
What type of error are you receiving? A quick look at your code shows that you aren't escaping the quotation marks correctly.

Code: Select all

<?php
 // example 1
 echo "<img src=\"path/to/file\" width=\"100\" height=\"100\" />";
 // example 2
 echo '<img src="path/to/file" width="100" height="100" />';
 // example 3
 echo 'Hello \'World\' ';
?>
If you are encassing your statements in double quote marks (") any double quotes inside the statement has to be escape, like in example 1. Same goes for single quotation marks (per example 3). I find that it's easier to use single quotes to encase when working with html where " is required i.e src="path/to/file".