Possible Duplicate:
pass php variable value to javascript
I have a piece of php code
function formLetterTabPage($redirect_url, $letter){
$test = 123;
foreach (range('A','Z') as $val) {
if($val == $letter){
echo '<li class="a" id="li_'.$letter.'" onclick="tab_click('.$letter.')">'.$letter.'</li>';
}else{
echo '<li class="b" id="li_'.$val.'" onclick="tab_click('.$letter.')">'.$val.'</li>';
}
}
}
and my javascript function tab_click is quite simple:
function tab_click(f){
alert(f);
}
the key part is here:
echo '<li class="a" onclick="tab_click('.$letter.')">'.$letter.'</li>';
it cannot work out ! so I change it like this:
$test = 123;
echo '<li class="a" onclick="tab_click('.$test .')">'.$letter.'</li>';
it works perfert, and the page show me 123! I wonder why this happen? And I checked the html code, it ok:
<li class="navi_letter_leftb" id="li_A" onclick="tab_click(A)">A</li>
ok, I don't know why?