Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    Jun 2007
    Location
    Los Angeles
    Posts
    545
    Thanks
    81
    Thanked 5 Times in 5 Posts

    Mixing PHP and JS in OnClick Event

    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>
    RalphF
    Business Text Messaging Services
    https://www.MobileTextingService.com

  • #2
    New to the CF scene
    Join Date
    Jul 2007
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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:

    Code:
    <? $width = 100; $height = 50; ?>
    The onClick will get populated with "100, 50"... so something must be wrong in your PHP code.

  • #3
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,068
    Thanks
    0
    Thanked 256 Times in 252 Posts
    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.
    Glenn
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •