Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

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?

share|improve this question
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 Answers

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;">
share|improve this answer
this.options[this.selectedIndex].value

Please pass the value of selected index like this

share|improve this answer

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

onclick="send(pid.value)"

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.