Log in

View Full Version : Passing PHP through to JS



at.varley
09-20-2007, 01:13 PM
Hey, I have some code where I want to pass a PHP parameter through to a javascript function. Basically I want the parameter in expand content to be identical to div id. I.E when the expandcontent function is called, the function calls the div id content to expand.
...bit unclean without variables but I just want it to work 1st.

Cheers


<h3 onClick="expandcontent(<?php echo $row_display_results['plan_name'];?>)" style="cursor:hand; cursor:pointer"><?php echo

$row_display_results['plan_name'];?></h3>
<div id="<?php echo $row_display_results['plan_name']; ?>" class="switchcontent">

boogyman
09-20-2007, 01:28 PM
that is perfectly acceptable, because the php is processed on the server side and the javascript isn't processed until the client-side by the browser interpreter, so the php will place in whatever value it returns from the php code

Twey
09-20-2007, 04:40 PM
You need quotes around it, however:
onclick="expandcontent('<?php echo addslashes($row_display_results['plan_name']); ?>');"