Q:

how to pass php parameter to javascript

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?

A:

You need additional quotes in your javascript for string parameters:
echo '<li class="a" onclick="tab_click(\''.$letter.'\')">'.$letter.'</li>';

In your test case $test = 123; you are passing an integer, so the quotes are not needed.
EDIT
Output without quotes (invalid javascript):
<li class="a" onclick="tab_click(a)">a</li>

Output with quotes:
<li class="a" onclick="tab_click('a')">a</li>

