Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
169
rated 0 times [  172] [ 3]  / answers: 1 / hits: 22968  / 13 Years ago, sat, september 24, 2011, 12:00:00

I want to change the value of value using a change event listener. Is it possible? Here is my sample code:



<select name=select1 onchange=updatevariable(this.value)> 
<option value=2 >2</option>
<option value=15 >15</option>
</select>
<script type=text/javascript>
value = test;
function updatevariable(data) {
value = data;
}
alert(value); // It should be 2/15
</script>

More From » javascript

 Answers
27

You have alert() in wrong place



<select name=select1 onchange=updatevariable(this.value)> 
<option value=2 >2</option>
<option value=15 >15</option>
</select>
<script type=text/javascript>
var value = test;
function updatevariable(data) {
value = data;
alert(value);
}
</script>


In your code it is loaded right after the script is loaded,

you have to modify it to be called right after change


[#89947] Thursday, September 22, 2011, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
keric

Total Points: 572
Total Questions: 93
Total Answers: 97

Location: Cyprus
Member since Mon, Oct 24, 2022
2 Years ago
;