Spin buttons to up quantity in javascript -


i have made spin control increments & decrements onclick event problem want restrict never allowed display below value of 1. when shows 1 , hit decrement arrow goes down 0 , there continue -1, -2, -3 etc etc

is ther way can add script/function make minimum quantity displayed 1

my function in head tag is:

  <!---spin buttons quantity--->    <script type="text/javascript">        function changeval(n) {             document.forms[0].quantity.value =    parseint(document.forms[0].quantity.value) + n;        }   </script>  

and field in form is:

 <td ><input name="quantity" type="text" class="quantity" onfocus="this.blur();" value="1" /></td>                      <td style="width:14px;">                            <table cellpadding="0" cellspacing="0">                        <td width="28"><img src="siteimages/btn_up.gif" width="14" height="9" hspace="0" vspace="0" border="0" onclick="changeval(1);"></td>                     </tr>                     <tr>                     <td><img src="siteimages/btn_down.gif" width="14" height="9" border="0" hspace="0" vspace="0" onclick="changeval(-1);"></td>                      </tr>  

use if condition check whether new value non zero, , change form element's value if case.

function changeval(n) {      var el = document.forms[0].quantity;     var newval = parseint(el.value) + n;     if (newval > 0) {         el.value = newval;     } }  

Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -