<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en"
"Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" >
<title> text boxes that support add and subtract operations </title>
<meta http-equiv= "Content-type" content= "text/html;charset=gb2312" >
<style type= "Text/css" >
Body{color: #000; Font-size:14px;font-family:verdana,arial,helvetica,sans-serif, "Song Body";}
Input{border-style:solid;border-color: #868275; Background-color: #f9f9f9; Border-width:1px;color: #505050; Vertical-align:middle;}
</style>
<script language=javascript>
function Floatadd (ARG1,ARG2) {
var r1,r2,m;
Try{r1=arg1.tostring (). Split (".") [1].length}catch (e) {r1=0}
Try{r2=arg2.tostring (). Split (".") [1].length}catch (e) {r2=0}
M=math.pow (10,math.max (R1,R2))
Return (arg1*m+arg2*m)/M
}
function Floatsubtr (ARG1,ARG2) {
Return Floatadd (ARG1,-ARG2);
}
function Ismoney (Money) {
if (/^[\d|+|.| -]+$/.test (Money)) return true;
return false;
}
function result () {
Str=document.getelementbyid ("buy"). Value;
if (! ( Ismoney (str))) {
document.getElementById ("Amount"). InnerHTML = "Invalid Amount";
return false;
}
var len=str.length,money=0,num=0;
var numstr= "", ctrlflag= "X", cflag=0;
for (var i=0;i<len; i++) {
c= Str.charat (i);
if ((c== "+") | | (c== "-")) {
if (I+1<len) {
if ((Str.charat (i+1) = = "+") | | (Str.charat (i+1) = = "-")) Continue
}
if ((numstr!= ") && (IsNaN (NUMSTR))) {
if (IsNaN (NUMSTR)) {
document.getElementById ("Amount"). InnerHTML = "Invalid amount entered";
return false;
}
}
if (numstr!= "") {
Alert ("I:" +i+ "NUMSTR:" +numstr);
if ((ctrlflag== "+") | | (ctrlflag== "x")) {
Num=parsefloat (NUMSTR);
Alert (ctrlflag+ "Money:" +money+ "Num:" +num);
Money=floatadd (Money,num);
Numstr= "";
num=0;
Ctrlflag=c;
}
else{
Alert (money+ "inside minus" +numstr);
Num=parsefloat (NUMSTR);
MONEY=FLOATSUBTR (Money,num);
Numstr= "";
num=0;
Ctrlflag=c;
}
}
else{
Ctrlflag=c;
}
Continue
}
else{
numstr=numstr+ "" +C;
}
}
if ((numstr!= ") && (IsNaN (NUMSTR))) {
if (IsNaN (NUMSTR)) {
document.getElementById ("Amount"). InnerHTML = "Invalid Amount" +NUMSTR;
return false;
}
}
if ((ctrlflag== "-") && (numstr!= "")) {
Num=parsefloat (NUMSTR);
MONEY=FLOATSUBTR (Money,num);
}
if ((ctrlflag== "+") | | (ctrlflag== "x")) && ((numstr!= ""))) {
Num=parsefloat (NUMSTR);
Money=floatadd (Money,num);
}
document.getElementById ("Amount"). InnerHTML =money;
}
</script>
<body>
Please enter add and subtract formula: <input id= "buy" name= "buy" maxlength= "" type= "text" onkeyup= "Javascript:result ();" >
<span id= "Amount" ></span>
</body>
<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en"
"Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" >
<title> text boxes that support add and subtract operations </title>
<meta http-equiv= "Content-type" content= "text/html;charset=gb2312" >
<style type= "Text/css" >
Body{color: #000; Font-size:14px;font-family:verdana,arial,helvetica,sans-serif, "Song Body";}
Input{border-style:solid;border-color: #868275; Background-color: #f9f9f9; Border-width:1px;color: #505050; Vertical-align:middle;}
</style>
<script language=javascript>
function Floatadd (ARG1,ARG2) {
var r1,r2,m;
Try{r1=arg1.tostring (). Split (".") [1].length}catch (e) {r1=0}
Try{r2=arg2.tostring (). Split (".") [1].length}catch (e) {r2=0}
M=math.pow (10,math.max (R1,R2))
Return (arg1*m+arg2*m)/M
}
function Floatsubtr (ARG1,ARG2) {
Return Floatadd (ARG1,-ARG2);
}
function Ismoney (Money) {
if (/^[\d|+|.| -]+$/.test (Money)) return true;
return false;
}
function result () {
Str=document.getelementbyid ("buy"). Value;
if (! ( Ismoney (str))) {
document.getElementById ("Amount"). InnerHTML = "Invalid Amount";
return false;
}
var len=str.length,money=0,num=0;
var numstr= "", ctrlflag= "X", cflag=0;
for (var i=0;i<len; i++) {
c= Str.charat (i);
if ((c== "+") | | (c== "-")) {
if (I+1<len) {
if ((Str.charat (i+1) = = "+") | | (Str.charat (i+1) = = "-")) Continue
}
if ((numstr!= ") && (IsNaN (NUMSTR))) {
if (IsNaN (NUMSTR)) {
document.getElementById ("Amount"). InnerHTML = "Invalid amount entered";
return false;
}
}
if (numstr!= "") {
Alert ("I:" +i+ "NUMSTR:" +numstr);
if ((ctrlflag== "+") | | (ctrlflag== "x")) {
Num=parsefloat (NUMSTR);
Alert (ctrlflag+ "Money:" +money+ "Num:" +num);
Money=floatadd (Money,num);
Numstr= "";
num=0;
Ctrlflag=c;
}
else{
Alert (money+ "inside minus" +numstr);
Num=parsefloat (NUMSTR);
MONEY=FLOATSUBTR (Money,num);
Numstr= "";
num=0;
Ctrlflag=c;
}
}
else{
Ctrlflag=c;
}
Continue
}
else{
numstr=numstr+ "" +C;
}
}
if ((numstr!= ") && (IsNaN (NUMSTR))) {
if (IsNaN (NUMSTR)) {
document.getElementById ("Amount"). InnerHTML = "Invalid Amount" +NUMSTR;
return false;
}
}
if ((ctrlflag== "-") && (numstr!= "")) {
Num=parsefloat (NUMSTR);
MONEY=FLOATSUBTR (Money,num);
}
if ((ctrlflag== "+") | | (ctrlflag== "x")) && ((numstr!= ""))) {
Num=parsefloat (NUMSTR);
Money=floatadd (Money,num);
}
document.getElementById ("Amount"). InnerHTML =money;
}
</script>
<body>
Please enter add and subtract formula: <input id= "buy" name= "buy" maxlength= "" type= "text" onkeyup= "Javascript:result ();" >
<span id= "Amount" ></span>
</body>
JS Implementation of text box support add and subtract operation method