Passing a PHP variable to JS

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
aceconcepts
DevNet Resident
Posts: 1424
Joined: Mon Feb 06, 2006 11:26 am
Location: London

Passing a PHP variable to JS

Post by aceconcepts »

Hi,

I have a javascript function that creates a popup div when you click on a link.

The "href" passes an id value to the JS function.

My problem is that each link that passes the id value is within a loop.

What I want to do is pass the value of the current record within the loop when the link is clicked so that that current value can be used to reference the correct record.

Here is my code:

Code: Select all

 
foreach($timeArray as $varTimeSlot)
{
    $content=$varTimeSlot;
    
    echo'<div style="overflow:auto; width:100%;">   
        <div class="timeSlotContainer timeRow">
        
            <div id="' . $varTimeSlot . '" class="timeSlotInnerContainer">' . date("g:ia", strtotime($varTimeSlot)) . '</div>
            
            <div style="float:left; padding:4px;">'; ?><a href="javascript&#058;showbox('div')">Show Div_ID1</a> | <a href="javascript&#058;hidebox('div')">Show Div_ID1</a><? echo'</div>
        
        </div>  
    </div>';
}
 
<script>
    window.onload=function(){
    new popUp(200, 100, 400, 300, "div", "<? echo $content; ?>", "white", "black", "bold 10pt sans-serif", "Appointment", "#0099cc", "white", "#0099cc", "gray", "black", false, true, true, true, false);
    }
</script>
 
As you can see from my code I am trying to get record specific content to appear in the "new popUp" but the way I have done it only passes the last record in the loop.

Any ideas how to pass record specific id/content to function?
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Re: Passing a PHP variable to JS

Post by s.dot »

Pass the id as a parameter to your function, then use it in the URI.
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
Post Reply