I can't figure out why this wont work. I'm trying to get a simple counter working. When a user clicks "yes" I want to increase the value of a hidden text box by 1. Currently, when I click yes, the text box's value changes to "102" and the appended text shows as "101102". Any ideas?
Here's the code I'm working with:
var yesValue = parseInt($("#trend-one-yes").val());
$("#trend-one-yes").val(yesValue+1);
var $addDiv = $('#yes');
$addDiv.append($("#trend-one-yes").val());
Update
I added some of the suggested code. It's still outputting the wrong number. It should be increasing by 1 instead its going up by 2. Thanks for your help!
<div id="vote" class="animated" data-fx="slideInDown">
<div class="vote-w">
<div class="vbut" id="yes"><div></div><div class="tag">Yes</div></div>
<div class="vbut" id="no"><div></div><div class="tag">No</div></div>
</div>
<div id="results">
<div class="res" id="yesNum"></div>
<div class="res" id="noNum"></div>
<form id="vals" method="post" action="data/save.php" target="sub">
<input id="trend-one-yes" name="trend-one-yes"
value="<?php echo $survey->one->yes?>"/>
<input id="trend-one-no" name="trend-one-no"
value="<?php echo $survey->one->no?>"/>
</form>
<iframe id="sub" frameborder="0" name="sub"
style="height:1px; width:1px;"></iframe>
</div>
And the script
<script>
$("#yes").mouseup(function()
{
$(this).css("color","#ffffff");
$('#results').slideDown({ duration: 1000, easing: "easeOutBounce" });
var $tyes = $("#trend-one-yes");
var count = parseInt($tyes.val(), 10) + 1
$tyes.val(count);
var $addDiv = $('#yesNum').text(count);
$( "#vals" ).submit();
});
</script>
Tried the code added below. Thanks again, but its still adding 2 instead of one. How can that be?