SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    Nov 2004
    Location
    Tifton, Ga
    Posts
    9
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Trying to pass a php id to javascript on the same page

    Hello Guys,

    I need some help here..

    I have a page that has a grid on it and I have a hidden div(below the grid). When the link is clicked inside the grid it opens the hidden div using the following code for the link in the grid.

    Here is my code with the PHP id that I need to pass

    PHP Code:
    foreach($ct->data as $key => $value){
       
    $ct->data[$key][3]='<a href=#" onclick="part2('.$ct->data[$key][0].');" href="javascript:void();">'.$ct->data[$key][3].'</a>'
    Trying to pass a php id to javascript on the same page


    Here is the code in my head
    Code:
    <script type="text/javascript">
    function part2(id) {
    var part2 = document.getElementById('part2');
       if ( part2.className == 'hidden' ) {
          part2.className = 'visible';
          document.getElementById('message').InnerHTML = 'This is the ID: '+id
       } else {
          part2.className = 'hidden';
       }
    }
    </script>
    Added this to my hidden div to show the id
    Code:
    <span id=message></span>
    Any help would be appreciated..

    Thanks, Dan

  2. #2
    SitePoint Wizard bronze trophy chris.upjohn's Avatar
    Join Date
    Apr 2010
    Location
    Melbourne, AU
    Posts
    2,198
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    The first issue i see is you have href=#" which isn't valid HTML markup and may affect the result you are wanting, if after you remove this and it still doesn't work would it be possible to get a link to a demo page for up close debugging.

  3. #3
    SitePoint Member
    Join Date
    Jul 2011
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The code will fail when javascript is used to jump from page to page. ... You don't need to include cookieless.php it will have been included already if needed.
    <snip>
    Last edited by samanime; Jul 20, 2011 at 22:44. Reason: No unnecessary links.


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
  •