Results 1 to 3 of 3

Thread: echo php inside javascript

  1. #1
    Join Date
    Sep 2011
    Posts
    35
    Thanks
    8
    Thanked 0 Times in 0 Posts

    Question echo php inside javascript

    PHP Code:
    <?php echo "<a href=images/".$rows['filename']. onclick="NewWindow(this.href,'Full Size Preview','400','400','yes','center');return false" onfocus="this.blur()">" . $rows['filename'] . "</a>"; ?>
    how to call javascript in php echo statement? As i mentioned in above statement i am getting error.
    Last edited by salman1karim; 11-06-2013 at 04:24 AM.

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    28,924
    Thanks
    43
    Thanked 3,187 Times in 3,151 Posts
    Blog Entries
    12

    Default

    You must escape like quotes:

    PHP Code:
    <?php echo "<a href='images/".$rows['filename']."' onclick=\"NewWindow(this.href,'Full Size Preview','400','400','yes','center');return false\" onfocus=\"this.blur()\">" $rows['filename'] . "</a>"?>
    Or, and this is probably a better way, echo less of the text:

    PHP Code:
    <a href="images/<?php echo $rows['filename'];?>" onclick="NewWindow(this.href,'Full Size Preview','400','400','yes','center');return false;" onfocus="this.blur();"><?php echo $rows['filename'];?></a>
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  3. The Following User Says Thank You to jscheuer1 For This Useful Post:

    salman1karim (11-06-2013)

  4. #3
    Join Date
    Sep 2011
    Posts
    35
    Thanks
    8
    Thanked 0 Times in 0 Posts

    Default

    Thanks Its working perfect.
    I am very thankful to you because 90% you helped me when i stuck in the coding.

Similar Threads

  1. echo double quotes for javascript
    By ggalan in forum PHP
    Replies: 4
    Last Post: 07-22-2010, 07:30 PM
  2. echo inside an echo?
    By crobinson42 in forum PHP
    Replies: 5
    Last Post: 05-20-2010, 02:32 AM
  3. Replies: 2
    Last Post: 04-04-2010, 04:16 PM
  4. Echo a part of a javascript
    By Null in forum PHP
    Replies: 2
    Last Post: 05-06-2006, 04:22 PM
  5. Replies: 14
    Last Post: 05-06-2006, 11:09 AM

Bookmarks

Posting Permissions

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