Javascript onchange event doesn't change div content
Posted
by
Eli_jun
on Stack Overflow
See other posts from Stack Overflow
or by Eli_jun
Published on 2013-10-22T03:45:00Z
Indexed on
2013/10/22
3:53 UTC
Read the original article
Hit count: 90
I want to replace the content of my <div id="score_here">10</div>
when I selecta value from my dropdown <select id="ansRate" onchange="javascript:add_score(this);">
. I have setup my javascript function shown below but it doesn't work, what is the problem with this? Thanks for the help. Here are my codes.
<div>
<select id="ansRate" onchange="javascript:add_score(this);">
<option value="0">Answer Rate</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
<option value="10">10</option>
</select>
</div>
<div id="score_here" style="width:100px;height:100px;background-color:yellow;">
81
</div>
<script type="text/javascript">
function add_score(a){
var string = $("#questionScore").text();
var thenum = string.replace( /^\D+/g, '');
var add = $(a).val();
var total = parseInt(thenum) + parseInt(add);
document.getElementByID('score_here').innerHTML = total;
}
</script>
© Stack Overflow or respective owner