...

View Full Version : Mixing PHP and JS in OnClick Event



rfresh
07-14-2007, 03: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?

Thanks...

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

Snocrash
07-14-2007, 08: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.

glenngv
07-14-2007, 07: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