Sunday, May 19, 2024
 Popular · Latest · Hot · Upcoming
101
rated 0 times [  106] [ 5]  / answers: 1 / hits: 100564  / 12 Years ago, tue, april 24, 2012, 12:00:00

I'm trying to change the value of a text box with the the item I select from a drop down box. But it's not working.



I tried this HTML:



<select name=ncontacts id=contacts onchange=ChooseContact(this);> 
</select>


and this JS:



function ChooseContact(data)
{
alert(data);
document.getElementById(friendName).value = data;
}


But the text box val is not updated.


More From » html

 Answers
15

This is because this (the argument to ChooseContact) refers to the select element itself, and not its value. You need to set the value of the friendName element to the value of the select element:



document.getElementById(friendName).value = data.value; //data is the element


Here's a working example.


[#86012] Monday, April 23, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
chase

Total Points: 78
Total Questions: 106
Total Answers: 93

Location: Comoros
Member since Tue, Mar 14, 2023
1 Year ago
;