<!DOCTYPE HTML Public "-//W3C//DTD XHTML 1.0 transitional//en" "http://www.w3.org/TR/xhtml1/DTD/ Xhtml1-transitional.dtd "><HTMLxmlns= "http://www.w3.org/1999/xhtml"><Head><Metahttp-equiv= "Content-type"content= "text/html; charset=utf-8" /><title>JS number plus minus</title><Scripttype= "Text/javascript"src= "Http://www.jb51.net/Public/js/jquery.min.js"></Script><Scripttype= "Text/javascript">$(function(){ $("#quantity"). KeyUp (function(){ if(IsNaN ($ ( This). Val ())||parseint ($ ( This). Val ())<1){ $( This). Val ("1"); $("#totalPrice"). HTML ($ ("#price"). Val ()); return; } var Total=parsefloat ($ ("#price"). Val ())*parseint ($ ( This). Val ()); $("#totalPrice"). HTML (total.tofixed (2)); })})/*number of items +1*/functionNumadd () {varNum_add=parseint ($ ("#quantity"). Val ())+1; if($("#quantity"). Val ()=="") {Num_add= 1; } $("#quantity"). Val (Num_add); var Total=parsefloat ($ ("#price"). Val ())*parseint ($ ("#quantity"). Val ()); $("#totalPrice"). HTML (total.tofixed (2));}/*number of items-1*/functionNumdec () {varNum_dec=parseint ($ ("#quantity"). Val ())-1; if(Num_dec<1){ //Purchase quantity must be greater than or equal to 1Alert ("Not LT 1"); }Else{ $("#quantity"). Val (Num_dec); var Total=parsefloat ($ ("#price"). Val ())*parseint ($ ("#quantity"). Val ()); $("#totalPrice"). HTML (total.tofixed (2)); }}</Script></Head><Body> <P>Quantity:<spanonclick= "Numdec ()">-</span> <inputtype= "text"ID= "Quantity" /> <spanonclick= "Numadd ()">+</span></P> <Pclass= "SDSD">Total Price:<spanID= "Totalprice">28.10</span></P> <inputtype= "hidden"value= "28.1"ID= "Price" /><!--Unit Price -</Body></HTML>
jquery example sharing of text box number plus and minus functions