How to update a number in html via javascript?
Posted
by
Will Merydith
on Stack Overflow
See other posts from Stack Overflow
or by Will Merydith
Published on 2011-01-07T21:30:26Z
Indexed on
2011/01/07
21:53 UTC
Read the original article
Hit count: 161
After a voter votes, I want to update the count.
<form class="vote-form" action="">
<div id="{{key}}" class="vote-count">{{votes}}</div>
<input class="vote-button" type="submit" class="text-button" value="vote+"/>
<input type="hidden" class="brag" name="brag" value="{{key}}">
<input type="hidden" class="voter" name="voter" value="{{current_user.fb_id}}">
</form>
<script type="text/javascript">
$(function() {
$('.error').hide();
$(".vote-form").submit(function() {
var inputs = $(this).find('input:hidden');
var key = $('input.brag', this).val();
$.ajax({
type: "POST",
url: "/bean",
data: inputs,
success: function() {
//not sure how to do this, I want to increment {{votes}}
$('#' + key).innerHTML = "foo";
}
});
return false;
});
});
</script>
© Stack Overflow or respective owner