javascript - Setting function decrement in variable onclick function -
please.. need thing.. wanna use variable id in html, call function in javascript page.
example: html
(minus button dont work)
<button class="minus-button quantity-button button" type="button" name="subtract" onclick="javascript: subtractdiv2(document.getelementbyid('<ccom:field id='code' />'));" value="-"> </button>
(this input quantity works normal)
<input class="quantity-input" value="<ccom:field id="qtd"/>" maxlength="3" id='<ccom:field id="code" />' name="div2" onkeypress="return somentenumerico(event);"/>
(plus button works normal)
<button class="plus-button quantity-button button" type="button" name="add" onclick="javascript:document.getelementbyid('<ccom:field id='code' />').value++;" value="+"></button>
javapage
function subtractdiv2(){ if(value - 1 < 0) return; else value--; };
you're not using argument function. should be:
function subtractdiv2(div) { var value = parseint(div.value, 10); if (value < 1) { return; } else { div.value = value - 1; } }
Comments
Post a Comment