Reputation: 205
I got an input type image with a javascript onclick event attached to it. Everytime I click the image it submits the form. I've already added the "return false", buts that that doesn't solve the problem. Here is my code:
<input type="image" onclick="incrementValue(@i)" value="+" />
Javascript
function incrementValue(n) {
var id = 'txtAantal' + n;
var value = parseInt(document.getElementById(id).value, 10);
value = isNaN(value) ? 0 : value;
value++;
document.getElementById(id).value = value;
var totaal = parseFloat(document.getElementById('txtTotaal').value, 10);
var prijs = parseFloat(document.getElementById('txtPrice' + n).value, 10);
document.getElementById('txtTotaal').value = totaal + prijs;
return false;
}
Upvotes: 0
Views: 7435
Reputation: 1852
Try this:
<input type="image" onclick="return incrementValue(@i)" value="+" />
Upvotes: 4
Reputation: 11
<button type="button" onclick="incrementValue(@i)" value="+" >
<img border="0" src="print.png" width="32" heigth="32" title="Click Me"/>
</button>
You should use a button and use type attribute like this
Upvotes: 1
Reputation: 3521
Try returning false after running the function:
<input type="image" onclick="incrementValue(@i); return false;" value="+" />
Upvotes: 2