将php变量传递给javascript [复制]

This question already has an answer here:

I have a dropdown list with name pid and a submit button in my form. when submit button is clicked i want to pass the value selected in the dropdown list (pid) to this var target_id in the javascript.

<script>
function send(fid)
{
var uid=fid;
alert('ID IS: '+uid);
}
</script>

echo "<select name='pid'>";
//this is in a for loop
echo "<option value=".$id.">".$id."</option>";
//for loop ends
</select>
<input type='submit' value='send' name='send' onclick='send(pid)' id='send'/>

what am i doing wrong here?

</div>
this.options[this.selectedIndex].value

Please pass the value of selected index like this

you have to put pid.value as the send function parameter like this

onclick="send(pid.value)"

Once the PHP renders into HTML it becomes less a question of passing PHP to Javascript and more a question or how to get the value from the HTML with Javascript. Would adding an onclick call to the function work for what you are trying to do?

<input type="submit" value="Submit" onclick="send(this.form.pid.value);return false;">