Page 1 of 1

Passing a variable from php to javascript

Posted: Tue Dec 16, 2008 4:00 pm
by sjk1000
Hi all
I think I'm missing the point here. Why can't I pass the $hello string to a javascript alert function? If i replace the $hello with 'hello world' it's all good. I've only today started tinkering with javascript so go easy on me. If you know of a good tutorial (video would be nice) please let me know.
Thanks, Steve

Code: Select all

<?php
$seller_count = 5;
$basket_items = 10;
for ($row=0; $row <=$basket_items; $row++)
{
    echo "<TR>";
    for ($column=0; $column <= $seller_count; $column ++)
    {
    $to_display = $row."--".$column.":";
    $hello ='hello world';
    ?> <TD> <?php echo $to_display ?> <input type=radio name="a" onclick= "alert($hello);"></TD> <?php
    }
    echo "</TR>";
}
?>

Re: Passing a variable from php to javascript

Posted: Tue Dec 16, 2008 4:46 pm
by Reviresco

Code: Select all

<?php
$seller_count = 5;
$basket_items = 10;
for ($row=0; $row <=$basket_items; $row++)
{
    echo "<TR>";
    for ($column=0; $column <= $seller_count; $column ++)
    {
    $to_display = $row."--".$column.":";
    $hello ='hello world';
    ?> <TD> <?php echo $to_display; ?> <input type=radio name="a" onclick= "alert('<?php echo $hello; ?>');"></TD> <?php
    }
    echo "</TR>";
}
?>

Re: Passing a variable from php to javascript

Posted: Tue Dec 16, 2008 5:17 pm
by sjk1000
Thanks for modifying that Reviresco. It's been driving me nuts for the last hour
Cheers, Steve