PHP echo and javascript

Soldato
Joined
5 Dec 2003
Posts
2,716
Location
Glasgow
Hey, I have a webpage displaying a table from a database. I am wanting to make one of the fields trigger a javascript function using the two previous fields as its parameters. I am having trouble passing the parameters to the javascript function using PHP as the line is full of quotation characters something like this:

echo '<td><a href="#" onclick=(' . $string1 . ', ' . $string2 . ')>' . $row[field3] . '</a></td>

That's the best I can recall from memory and it throws up a javascript error. Does anyone know how I can do this?
 
What is meant by escape?

basically being out of "this" and 'this' although "$this" will work just as well as .$this.... sooooo:

$this = "test";
$variable1 = "$this";
$variable2 = $this;

echo "$variable1 is the same as $variable2"

you'll end up with "test is the same as test"

:)

but to answer:
echo '<td><a href="#" onclick=(' . $string1 . ', ' . $string2 . ')>' . $row[field3] . '</a></td>

try
echo "<td><a href='#' onclick=('$string1, $string2')>" .$row['field3'] ."</a></td>";

or try
echo "<td><a href='#' onclick=('$string1, $string2')>$row['field3']</a></td>";

just noticed at the end of your script you didn't close the echo with '; that will definately kill it.
 
Last edited:
Back
Top Bottom