SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Member
    Join Date
    May 2007
    Posts
    18
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question pass a PHP variable to a Javascript toggle window

    I am trying to pass a PHP variable to my Javascript toggle window.

    normally to pass along my variable i would write something like this:

    http://www.hello.com?id=$id

    but instead of using a new URL I am using a toggle window. The code looks like this:

    Code:
    <script type="text/JavaScript">
    <!-- Show/Hide Pop-Up
    function toggleBox(szDivID, iState) // 1 visible, 0 hidden
    {
        if(document.layers)	   //NN4+
        {
           document.layers[szDivID].visibility = iState ? "show" : "hide";
        }
        else if(document.getElementById)	  //gecko(NN6) + IE 5+
        {
            var obj = document.getElementById(szDivID);
            obj.style.visibility = iState ? "visible" : "hidden";
        }
        else if(document.all)	// IE 4
        {
            document.all[szDivID].style.visibility = iState ? "visible" : "hidden";
        }
    }
    // -->
    Code:
    // Display each phone number
    while ($phon = mysql_fetch_array($result)) {
      $phId = ($phon['id']); // Phone ID
      $phone_title = $phon['phone_title'];
      		if ($phone_title == 1) { $phone_title = "Campus Phone Number"; }
    		if ($phone_title == 2) { $phone_title = "Cell Phone Number"; }
    		if ($phone_title == 3) { $phone_title = "Emergency Phone Number"; }
    		if ($phone_title == 4) { $phone_title = "Main Phone Number"; }
    		if ($phone_title == 5) { $phone_title = "Work Phone Number"; }
      $ph1 = ($phon['ph1']);
      $ph2 = ($phon['ph2']);
      $ph3 = ($phon['ph3']);	
      $ph_notes = ($phon['ph_notes']);
    ?>
    
    <a href="javascript:void('');" onClick="toggleBox('edit_phone',1);">EDIT</a>
    
    <? } ?>

    How do I pass along the php variable ($phID) so that when the new layer appears it can gather the correct information from my database?

  2. #2
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,526
    Mentioned
    83 Post(s)
    Tagged
    3 Thread(s)
    The best place to put $phID is in the section with an identifier of "edit_phone".
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript


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
  •