Results 1 to 3 of 3

Thread: Passing PHP through to JS

  1. #1
    Join Date
    Sep 2007
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Passing PHP through to JS

    Hey, I have some code where I want to pass a PHP parameter through to a javascript function. Basically I want the parameter in expand content to be identical to div id. I.E when the expandcontent function is called, the function calls the div id content to expand.
    ...bit unclean without variables but I just want it to work 1st.

    Cheers


    <h3 onClick="expandcontent(<?php echo $row_display_results['plan_name'];?>)" style="cursor:hand; cursorointer"><?php echo

    $row_display_results['plan_name'];?></h3>
    <div id="<?php echo $row_display_results['plan_name']; ?>" class="switchcontent">

  2. #2
    Join Date
    Jul 2006
    Location
    just north of Boston, MA
    Posts
    1,806
    Thanks
    13
    Thanked 72 Times in 72 Posts

    Default

    that is perfectly acceptable, because the php is processed on the server side and the javascript isn't processed until the client-side by the browser interpreter, so the php will place in whatever value it returns from the php code

  3. #3
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    You need quotes around it, however:
    Code:
    onclick="expandcontent('<?php echo addslashes($row_display_results['plan_name']); ?>');"
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh 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
  •