How do I add a value to a text box? For example, the amount? This is how I get an object from the DOM - what should I do?
$(this).parent("div").children("input").val();
This is the value of my textbox :)
var elm = $(this).parent("div").children("input"); var val = elm.val(); val = Number(val) == NaN ? 0 : Number(val); elm.val(val + 1);
Using jQuery, also handling empty condition when there is no value
inp = $("#inputId"); var orgValue = parseInt(inp.val() == "" ? "0" : inp.val()); inp.val((orgValue == NaN ? 0 : orgValue) + 1);