SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Member
    Join Date
    May 2006
    Posts
    23
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How to call this javascript function

    I have the following code:

    HTML Code:
    <html>
    <head>
    <script type='text/javascript'>
    function enlarge(table, master_id) {
    window.open("../admin/include/getImage.php?table="+table+"&master_id="+master_id+"&type=larger_image", "mywindow", "status=0, toolbar=0, scrollbars=1, menubar=0, width=400, height=400");
    }
    </script>
    </head>
    
    <body>
    
    <h1> my site </h1>
    PHP Code:
    <?php
    echo "<a style='border: 0px;' href='#' onClick='enlarge('images', $main_product_id);><img style='border: 0px;' src='images/button-magnify-yel.gif'>";
    ?>
    HTML Code:
    </body>
    </html>
    OK, the function works fine, however, I'm trying to call it using from within a link which is being echoed by PHP. However, I can't figure out how to call it, as there are too many ' and ".

    I am closing it like so:

    echo "<a href='#' onClick='enlarge(' .......

    So how do I organise it, to call it, whilst passing the values successfully?

    Thanks.

  2. #2
    ✯✯✯ silver trophybronze trophy php_daemon's Avatar
    Join Date
    Mar 2006
    Posts
    5,284
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    <?php
    echo '<a style="border: 0px;" href="#" onClick="enlarge(\'images\', '.$main_product_id.');"><img style="border: 0px;" src="images/button-magnify-yel.gif" />';
    ?>
    Saul

  3. #3
    SitePoint Wizard stereofrog's Avatar
    Join Date
    Apr 2004
    Location
    germany
    Posts
    4,324
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Escaping from php to html mode is the best way to avoid quoting issues:

    Code:
    #php code ends here
    ?>
    <a 
    style="border: 0px;" href="#" 
    onclick="enlarge('images', '<?php echo $main_product_id?>')">
    <img style="border: 0px;" src="images/button-magnify-yel.gif">
    </a>
    <?php 
    #php continues here

  4. #4
    SitePoint Member
    Join Date
    May 2006
    Posts
    23
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks guys.

    I think I'll use php_daemon's way, just for consistency, as the rest of my html code is being echo'd from PHP.


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
  •