0

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?

Scorpion King
  • 1,878
  • 8
  • 38
  • 45
  • Could you post the full code, rather than leaving mysterious comments? Showing us what's happening in the loop might be more useful. – David Thomas Jan 30 '11 at 20:20
  • it is a very big code... i have grabbed the value from the dropdown and echoed it to verfiy it. the loop is all fine. I just want to execute a javascript function when submit is clicked. – Scorpion King Jan 30 '11 at 20:34

3 Answers3

2

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;">
Levi
  • 12,214
  • 14
  • 43
  • 47
0
this.options[this.selectedIndex].value

Please pass the value of selected index like this

IDev
  • 1,221
  • 1
  • 11
  • 25
0

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

onclick="send(pid.value)"

Muhamad Bhaa Asfour
  • 1,075
  • 3
  • 22
  • 39