I have a form that looks like this:
I don't get how return false
and preventDefault
failed to do their job. Maybe try replacing the image buttons with linked images:
<a href="#" class="vote_down"><img src="vote_down.png"/></a>
$('#vote_form > a').click(function(e) {
e.preventDefault();
//one way to know which image was clicked
alert($(this).attr('class'));
$.post(...
});
You can always ensure that a form does not submit by binding to the submit event, e.g.:
$('#vote_form').submit(function() {
return false;
});
Try adding onsubmit="return false;" to your form, and then submitting your form with javascript:
<form action="/vote/" method="post" name="vote_form" class="vote_form" onsubmit="return false;">
<input type="hidden" name="question_id" value="10" />
<input type="image" src="vote_down.png" class="vote_down" name="submit" value="down" onclick="imageClicked(this)"/>
<input type="image" src="vote_up.png" class="vote_up" name="submit" value="up" onclick="imageClicked(this)"/>
</form>
<script>
function imageClicked(img) {
alert(img.className);
document.forms["vote_form"].submit();
}
</script>