Friday, May 10, 2024
 Popular · Latest · Hot · Upcoming
184
rated 0 times [  186] [ 2]  / answers: 1 / hits: 49089  / 10 Years ago, fri, september 19, 2014, 12:00:00

Im trying to modify the text of the first select option via javascript.
But it empties the entire select option



 <select name='stuff'>
<option value=a> Pepsi </option>
<option value= b> Juice </option>
</select>


<script type=text/javascript>
document.getElementsByName('stuff')[0].innerHTML = Water;
</script>

More From » html

 Answers
4

You want to read from the options collection and modify the first element in there:



document.getElementsByName('stuff')[0].options[0].innerHTML = Water;

[#69397] Wednesday, September 17, 2014, 10 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
mckinleyi

Total Points: 121
Total Questions: 100
Total Answers: 109

Location: Peru
Member since Fri, Oct 14, 2022
2 Years ago
;