View Full Version : Mixing PHP and JS in OnClick Event

07-14-2007, 02:50 AM
I'm having a hard time getting PHP variable values inserted into an OnClick event. My PHP vars $width and $height in the JS event below are not carrying their values into the JS function - am I using the wrong PHP syntax?


<A HREF="http://www.yoursite.com?>/<?php echo $php_large_photo_filename?>" onClick="return popup(this, 'Notes', <?php echo $width?>, <?php echo $height?>)"></A>

07-14-2007, 07:46 AM
The PHP syntax is correct... it's just that your PHP vars aren't being assigned a value. Try adding this right before the anchor:

<? $width = 100; $height = 50; ?>

The onClick will get populated with "100, 50"... so something must be wrong in your PHP code.

07-14-2007, 06:31 PM
Are the values numeric or string like '12px'? If the latter, then you need to enclose the values in quotes. It would help if you post the generated source.

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum