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?

2
  • Could you post the full code, rather than leaving mysterious comments? Showing us what's happening in the loop might be more useful. Commented Jan 30, 2011 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. Commented Jan 30, 2011 at 20:34

3 Answers 3

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;">
Sign up to request clarification or add additional context in comments.

Comments

0
this.options[this.selectedIndex].value

Please pass the value of selected index like this

Comments

0

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

onclick="send(pid.value)"

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.