Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 236
  • Last Modified:

How to convert a value to 0 when the result of the text field is equal to negative value like -1,-1234,-2324324.

How to convert a value to 0 when the result of the text field is equal to negative value like -1,-1234,-2324324?

Lets say i have 3 text field here. I name the text fields with textfield a+textfield b+textfield c=textfield d.

If the result of the text field is equal to -1 or any negatif number, then the result appear in the text field d should be 0. But if it is a positive number, then let the aritmethic calculation count.

Please provide answer in javascript ofr vbscript.Thanks
0
inzhagi
Asked:
inzhagi
  • 2
  • 2
1 Solution
 
RozanaZCommented:
<HTML>
<HEAD>
<TITLE></TITLE>

<script>
      function test()
      {
            text_a = document.getElementById("textfield_a").value;
            text_b = document.getElementById("textfield_b").value;
            text_c = document.getElementById("textfield_c").value;
            result = eval(text_a) + eval(text_b) + eval(text_c);
            if(result < 0)
            {
                  document.getElementById("textfield_d").value = "0";
            }
            else
            {
                  document.getElementById("textfield_d").value = result;
            }
      }
</script>
</HEAD>
<BODY>
<table>
      <tr>
            <td>
                  <form name="f1" id="f1" action="http://1.1.1">
                        a:<input type="text" id="textfield_a" ><br>
                        b:<input type="text" id="textfield_b" ><br>
                        c:<input type="text" id="textfield_c" ><br>
                        result: <input type="text" id="textfield_d" ><br>
                        <input type="button" onClick="javascript: test()" value="Calculate">
                  </form>
            </td>
      </tr>
</table>
</BODY>
</HTML>
0
 
inzhagiAuthor Commented:
Actually you have give me some idea...but can u try to look at this code..u just save this code to a html file and try to look at the calculator function. I want the result to be zero if the answer value is negative number....


<HTML>
<HEAD>
<TITLE>Borang BE 2004</TITLE>
<script language="JavaScript" type="text/JavaScript">
<!--


function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_validateForm() { //v4.0
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
    if (val) { nm=val.name; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
      } else if (test!='R') { num = parseFloat(val);
        if (isNaN(val)) errors+='- '+nm+' Nilai nombor sahaja      .\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (num<min || max<num) errors+='- '+nm+'    Nilai haruslah tidak melebihi dari nilai yang ditetapkan. RM '+min+' hingga '+max+' sahaja.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
  } if (errors) alert('Maaf anda telah memasukkan nilai yang tidak sah.      \n'+errors);
  document.MM_returnValue = (errors == '');
}

function KW_getVal(o){ //v1.2
      var retVal="0";if (o.type=="select-one")
      {retVal=(o.selectedIndex==-1)?0:o.options[o.selectedIndex].value;}
      else if (o.length>1){for (var i=0;i<o.length;i++) if (o[i].checked) retVal=o[i].value;
      } else if (o.type=="checkbox") {retVal=(o.checked)?o.value:0;} else {
      retVal=Number(o.value)}return parseFloat(retVal);
}

function KW_calcForm() { //v1.2
      var str="",a=KW_calcForm.arguments; for (var i=3;i<a.length;i++)
      str+=(a[i].indexOf("#")==-1)?a[i]:KW_getVal(MM_findObj(a[i].substring(1)));
      t=Math.round(a[1]*eval(str))/a[1];tS=t.toString();if(a[2]>0){tSp=tS.indexOf(".");
      if(tSp==-1)      tS+=".";tSp=tS.indexOf(".");while(tSp!=(tS.length-1-a[2])){tS+="0";
      tSp=tS.indexOf(".");}} MM_findObj(a[0]).value=tS;
}
//-->
</script>
<style type="text/css">
<!--
body {
      background-image: url();
}
a:link {
      color: #FF0000;
}
a:visited {
      color: #FF0000;
}
a:hover {
      color: #0000FF;
}
a:active {
      color: #FF0000;
}
-->
</style>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script language="JavaScript" type="text/JavaScript">
<!--
function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);
//-->
</script>
</HEAD>

<BODY>
<FORM NAME="frmcal" method="post" action="calculator2.asp">
  <p align="center">&nbsp;  </p>
  <TABLE align="center" width="80%" border="1" bordercolor="#AADDEC" cellspacing="1" cellpadding="2">
    <TR>
      <td class="first" width="88%" height="10" valign="center" colspan="2">
        <div align="center">
          <p align="left">&nbsp;</p>
        </div>
      </td>
      <td width="6%" class="first" valign="center" height="10">
        <div align="center">
          <p><font face="Tahoma" size="2">Code</font></p>
        </div>
      </td>
      <td width="6%" class="first" valign="center" height="10">
        <div align="center">
          <p><font face="Tahoma" size="2">$</font></p>
        </div>
      </td>
    </TR>
    <TR bgcolor="#FFFFFF">
      <TD height="20"><font class="sixth">&nbsp;C1&nbsp;</font> <b></b></TD>
      <TD height="20"><b><font face="Tahoma" size="2">A</font></b></TD>
      <TD height="20">
        <div align="center"><b><font face="Tahoma" size="2">C1</font></b></div>
      </TD>
      <TD height="20">
        <div align="right">
          <input name="penggajian" class="fourth" onBlur="MM_validateForm('penggajian','','NisNum');return document.MM_returnValue" size=12 maxlength="12">
        </div>
      </TD>
    </TR>
    <TR bgcolor="#FFFFFF">
      <TD height="20"><font class="sixth">&nbsp;C2&nbsp;</font> <font face="Tahoma" size="2"></font></TD>
      <TD height="20"><font face="Tahoma" size="2"><b>B</b></font></TD>
      <TD height="20">
        <div align="center"><b><font face="Tahoma" size="2">C2 </font></b></div>
      </TD>
      <TD height="20">
        <input name="dividen" class="fourth" onBlur="MM_validateForm('dividen','','NisNum');return document.MM_returnValue" size=12 maxlength="12">
      </TD>
    </TR>
    <TR bgcolor="#FFFFFF">
      <TD><font class="sixth">&nbsp;C3&nbsp;</font> <b></b></TD>
      <TD><b><font face="Tahoma" size="2">C</font></b></TD>
      <TD>
        <div align="center"><b><font face="Tahoma" size="2">C3 </font></b></div>
      </TD>
      <TD>
        <input name="faedah" class="fourth" onBlur="MM_validateForm('faedah','','NisNum');return document.MM_returnValue" size=12 maxlength="12">
      </TD>
    </TR>
    <TR bgcolor="#FFFFFF">
      <TD><font class="sixth">&nbsp;C4&nbsp;</font> <b></b></TD>
      <TD><b><font face="Tahoma" size="2">D</font></b></TD>
      <TD>
        <div align="center"><b><font face="Tahoma" size="2">C4 </font></b></div>
      </TD>
      <TD>
        <input name="SEWA" class="fourth" onBlur="MM_validateForm('SEWA','','NisNum');return document.MM_returnValue" size=12 maxlength="12">
      </TD>
    </TR>
    <TR bgcolor="#FFFFFF">
      <TD><font class="sixth">&nbsp;C5&nbsp;</font> <b></b></TD>
      <TD><b><font face="Tahoma" size="2">E</font></b></TD>
      <TD>
        <div align="center"><b><font face="Tahoma" size="2">C5 </font></b></div>
      </TD>
      <TD>
        <input name="pencen" class="fourth" onBlur="MM_validateForm('pencen','','NisNum');return document.MM_returnValue" size=12 maxlength="12">
      </TD>
    </TR>
    <TR bgcolor="#FFFFFF">
      <TD><font class="sixth">&nbsp;C6&nbsp;</font> <b></b></TD>
      <TD><b><font face="Tahoma" size="2">F</font></b></TD>
      <TD>
        <div align="center"><b><font face="Tahoma" size="2">C6 </font></b></div>
      </TD>
      <TD>
        <input name="apa" class="fourth" onBlur="MM_validateForm('apa','','NisNum');return document.MM_returnValue" size=12 maxlength="12">
      </TD>
    </TR>
    <TR bgcolor="#B6D5FA">
      <TD height="34" class="third"><font class="sixth">&nbsp;C7&nbsp;</font>
        <b></b></TD>
      <TD height="34" class="third"><b><font face="Tahoma" size="2">Total (C1+C2+c3+c4+c5+C6=c7)</font></b></TD>
      <TD height="34" class="third">
        <div align="center"><b><font face="Tahoma" size="2">C7 </font></b></div>
      </TD>
      <TD height="34" class="third">
        <input name="pendapatanagregat" type="text" class="fourth" id="pendapatanagregat" onBlur="KW_calcForm('pendapatanagregat',1,-1,'#penggajian','+','#dividen','+','#faedah','+','#SEWA','+','#pencen','+','#apa')" size="12" maxlength="12" readonly="true">
      </TD>
    </TR>
    <TR bgcolor="#B6D5FA">
      <td bgcolor="#FFFFFF"><font face="Tahoma" size="1"><b></b></font></td>
      <TD height="21"  bgcolor="#FFFFFF" class="third"><b><font size="2" face="Tahoma">Minus or subtract </font></b></TD>
    </TR>
    <TR bgcolor="#FFFFFF">
      <TD height="36"><font class="sixth">&nbsp;C8&nbsp;</font> <b><font face="Tahoma" size="2"><br>
        </font></b></TD>
      <TD height="36"><b><font face="Tahoma" size="2">A</font></b></TD>
      <TD height="36">
        <div align="center"><font face="Tahoma" size="2"><b>C8</b></font></div>
      </TD>
      <TD height="36">
        <input name="C8" class="fourth" onBlur="MM_validateForm('C8','','NisNum');return document.MM_returnValue" size=12 maxlength="12">
      </TD>
    </TR>
    <TR bgcolor="#FFFFFF">
      <TD><font class="sixth">&nbsp;C9&nbsp;</font> <b></b></TD>
      <TD><b><font face="Tahoma" size="2">B</font></b></TD>
      <TD>
        <div align="center"><font face="Tahoma" size="2"><b>C9</b></font></div>
      </TD>
      <TD>
        <input name="C9" class="fourth" onBlur="MM_validateForm('C9','','NisNum');return document.MM_returnValue" size=12 maxlength="12">
      </TD>
    </TR>
    <TR bgcolor="#FFFFFF">
      <TD><font class="sixth">&nbsp;C10&nbsp;</font> <b></b></TD>
      <TD><b><font face="Tahoma" size="2">C</font></b></TD>
      <TD>
        <div align="center"><font face="Tahoma" size="2"><b>C10</b></font></div>
      </TD>
      <TD>
        <input name="C10" class="fourth" onBlur="MM_validateForm('C10','','NinRange0:20000');return document.MM_returnValue" size=12 maxlength="12">
      </TD>
    </TR>
    <TR bgcolor="#FFFFFF">
      <TD><font class="sixth">&nbsp;C11&nbsp;</font> <b></b></TD>
      <TD><b><font face="Tahoma" size="2">D</font></b></TD>
      <TD>
        <div align="center"><font face="Tahoma" size="2"><b>C11</b></font></div>
      </TD>
      <TD>
        <input name="C11" class="fourth" onBlur="MM_validateForm('C11','','NisNum');return document.MM_returnValue" size=12 maxlength="12">
      </TD>
    </TR>
    <TR bgcolor="#FFFFFF">
      <TD><font class="sixth">&nbsp;C12&nbsp;</font> <b></b></TD>
      <TD><b><font face="Tahoma" size="2">E</font></b></TD>
      <TD>
        <div align="center"><b><font face="Tahoma" size="2">C12</font></b></div>
      </TD>
      <TD>
        <input name="C12" class="fourth" onBlur="MM_validateForm('C12','','NisNum','C12','','NinRange0:20000');return document.MM_returnValue" size=12 maxlength="12">
      </TD>
    </TR>
    <TR bgcolor="#FFFFFF">
      <TD><font class="sixth">&nbsp;C13&nbsp;</font> <b></b></TD>
      <TD><b><font face="Tahoma" size="2">F</font></b></TD>
      <TD>
        <div align="center"><b><font face="Tahoma" size="2">C13</font></b></div>
      </TD>
      <TD>
        <input name="C13" class="fourth" onBlur="MM_validateForm('C13','','NisNum');return document.MM_returnValue" size=12 maxlength="12">
      </TD>
    </TR>
    <TR bgcolor="#94C6F8">
      <TD bgcolor="#94C6F8" class="third"><font class="sixth">&nbsp;C14&nbsp;</font>
        <b></b></TD>
      <TD bgcolor="#94C6F8" class="third"><b><font size="2" face="Tahoma">Total (c8+c9+c10+c11+c12=c14)</font></b></TD>
      <TD class="third">
        <div align="center"><b><font face="Tahoma" size="2">C14</font></b></div>
      </TD>
      <TD class="third">
        <input name="C14" type="text" class="fourth" onBlur="KW_calcForm('C14',1,-1,'#C8','+','#C9','+','#C10','+','#C11','+','#C12','+','#C13')" size=12 maxlength="12" readonly="true">
      </TD>
    </TR>
    <TR bgcolor="#FFFFFF">
      <TD class="fifth"><font class="sixth">&nbsp;C15&nbsp;</font> <b></b></TD>
      <TD class="fifth"><b><font size="2" face="Tahoma">G</font></b></TD>
      <TD>
        <div align="center"><b><font face="Tahoma" size="2">C15</font></b></div>
      </TD>
      <TD>
        <input name="C15" class="fourth" onBlur="MM_validateForm('C15','','NisNum');return document.MM_returnValue" size=12 maxlength="12">
      </TD>
    </TR>
    <TR bgcolor="#94C6F8">
      <TD class="third"><font class="sixth">&nbsp;C16&nbsp;</font> <b></b></TD>
      <TD class="third"><b><font size="2" face="Tahoma">Result (C7-C14-C15=C16)</font></b></TD>
      <TD class="third">
        <div align="center"><b><font face="Tahoma" size="2">C16</font></b></div>
      </TD>
      <TD class="third">
        <input name="C16" type="text" class="fourth" onBlur="KW_calcForm('C16',1,-1,'#pendapatanagregat','-','#C14','-','#C15')" size=12 maxlength="12" readonly="true">
     
        </TD>
    </TR>
  </TABLE>
  <p>&nbsp;</p>
  <p><br>
    <font face="Verdana, Arial, Helvetica, sans-serif" color=Gray size=1><br>
  </font> </p>
</FORM>

</BODY>

</HTML>

0
 
RozanaZCommented:
I fixed  KW_calcForm() function, so please try this:

<HTML>
<HEAD>
<TITLE>Borang BE 2004</TITLE>
<script language="JavaScript" type="text/JavaScript">
<!--


function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_validateForm() { //v4.0
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
    if (val) { nm=val.name; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
      } else if (test!='R') { num = parseFloat(val);
        if (isNaN(val)) errors+='- '+nm+' Nilai nombor sahaja     .\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (num<min || max<num) errors+='- '+nm+'    Nilai haruslah tidak melebihi dari nilai yang ditetapkan. RM '+min+' hingga '+max+' sahaja.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
  } if (errors) alert('Maaf anda telah memasukkan nilai yang tidak sah.     \n'+errors);
  document.MM_returnValue = (errors == '');
}

function KW_getVal(o){ //v1.2
     var retVal="0";if (o.type=="select-one")
     {retVal=(o.selectedIndex==-1)?0:o.options[o.selectedIndex].value;}
     else if (o.length>1){for (var i=0;i<o.length;i++) if (o[i].checked) retVal=o[i].value;
     } else if (o.type=="checkbox") {retVal=(o.checked)?o.value:0;} else {
     retVal=Number(o.value)}return parseFloat(retVal);
}

function KW_calcForm() { //v1.2
     var str="",a=KW_calcForm.arguments; for (var i=3;i<a.length;i++)
     str+=(a[i].indexOf("#")==-1)?a[i]:KW_getVal(MM_findObj(a[i].substring(1)));
     t=Math.round(a[1]*eval(str))/a[1];tS=t.toString();if(a[2]>0){tSp=tS.indexOf(".");
     if(tSp==-1)     tS+=".";tSp=tS.indexOf(".");while(tSp!=(tS.length-1-a[2])){tS+="0";
     tSp=tS.indexOf(".");}} if(tS < 0){tS = 0;} MM_findObj(a[0]).value=tS;
}
//-->
</script>
<style type="text/css">
<!--
body {
     background-image: url();
}
a:link {
     color: #FF0000;
}
a:visited {
     color: #FF0000;
}
a:hover {
     color: #0000FF;
}
a:active {
     color: #FF0000;
}
-->
</style>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script language="JavaScript" type="text/JavaScript">
<!--
function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);
//-->
</script>
</HEAD>

<BODY>
<FORM NAME="frmcal" method="post" action="calculator2.asp">
  <p align="center">&nbsp;  </p>
  <TABLE align="center" width="80%" border="1" bordercolor="#AADDEC" cellspacing="1" cellpadding="2">
    <TR>
      <td class="first" width="88%" height="10" valign="center" colspan="2">
        <div align="center">
          <p align="left">&nbsp;</p>
        </div>
      </td>
      <td width="6%" class="first" valign="center" height="10">
        <div align="center">
          <p><font face="Tahoma" size="2">Code</font></p>
        </div>
      </td>
      <td width="6%" class="first" valign="center" height="10">
        <div align="center">
          <p><font face="Tahoma" size="2">$</font></p>
        </div>
      </td>
    </TR>
    <TR bgcolor="#FFFFFF">
      <TD height="20"><font class="sixth">&nbsp;C1&nbsp;</font> <b></b></TD>
      <TD height="20"><b><font face="Tahoma" size="2">A</font></b></TD>
      <TD height="20">
        <div align="center"><b><font face="Tahoma" size="2">C1</font></b></div>
      </TD>
      <TD height="20">
        <div align="right">
          <input name="penggajian" class="fourth" onBlur="MM_validateForm('penggajian','','NisNum');return document.MM_returnValue" size=12 maxlength="12">
        </div>
      </TD>
    </TR>
    <TR bgcolor="#FFFFFF">
      <TD height="20"><font class="sixth">&nbsp;C2&nbsp;</font> <font face="Tahoma" size="2"></font></TD>
      <TD height="20"><font face="Tahoma" size="2"><b>B</b></font></TD>
      <TD height="20">
        <div align="center"><b><font face="Tahoma" size="2">C2 </font></b></div>
      </TD>
      <TD height="20">
        <input name="dividen" class="fourth" onBlur="MM_validateForm('dividen','','NisNum');return document.MM_returnValue" size=12 maxlength="12">
      </TD>
    </TR>
    <TR bgcolor="#FFFFFF">
      <TD><font class="sixth">&nbsp;C3&nbsp;</font> <b></b></TD>
      <TD><b><font face="Tahoma" size="2">C</font></b></TD>
      <TD>
        <div align="center"><b><font face="Tahoma" size="2">C3 </font></b></div>
      </TD>
      <TD>
        <input name="faedah" class="fourth" onBlur="MM_validateForm('faedah','','NisNum');return document.MM_returnValue" size=12 maxlength="12">
      </TD>
    </TR>
    <TR bgcolor="#FFFFFF">
      <TD><font class="sixth">&nbsp;C4&nbsp;</font> <b></b></TD>
      <TD><b><font face="Tahoma" size="2">D</font></b></TD>
      <TD>
        <div align="center"><b><font face="Tahoma" size="2">C4 </font></b></div>
      </TD>
      <TD>
        <input name="SEWA" class="fourth" onBlur="MM_validateForm('SEWA','','NisNum');return document.MM_returnValue" size=12 maxlength="12">
      </TD>
    </TR>
    <TR bgcolor="#FFFFFF">
      <TD><font class="sixth">&nbsp;C5&nbsp;</font> <b></b></TD>
      <TD><b><font face="Tahoma" size="2">E</font></b></TD>
      <TD>
        <div align="center"><b><font face="Tahoma" size="2">C5 </font></b></div>
      </TD>
      <TD>
        <input name="pencen" class="fourth" onBlur="MM_validateForm('pencen','','NisNum');return document.MM_returnValue" size=12 maxlength="12">
      </TD>
    </TR>
    <TR bgcolor="#FFFFFF">
      <TD><font class="sixth">&nbsp;C6&nbsp;</font> <b></b></TD>
      <TD><b><font face="Tahoma" size="2">F</font></b></TD>
      <TD>
        <div align="center"><b><font face="Tahoma" size="2">C6 </font></b></div>
      </TD>
      <TD>
        <input name="apa" class="fourth" onBlur="MM_validateForm('apa','','NisNum');return document.MM_returnValue" size=12 maxlength="12">
      </TD>
    </TR>
    <TR bgcolor="#B6D5FA">
      <TD height="34" class="third"><font class="sixth">&nbsp;C7&nbsp;</font>
        <b></b></TD>
      <TD height="34" class="third"><b><font face="Tahoma" size="2">Total (C1+C2+c3+c4+c5+C6=c7)</font></b></TD>
      <TD height="34" class="third">
        <div align="center"><b><font face="Tahoma" size="2">C7 </font></b></div>
      </TD>
      <TD height="34" class="third">
        <input name="pendapatanagregat" type="text" class="fourth" id="pendapatanagregat" onBlur="KW_calcForm('pendapatanagregat',1,-1,'#penggajian','+','#dividen','+','#faedah','+','#SEWA','+','#pencen','+','#apa')" size="12" maxlength="12" readonly="true">
      </TD>
    </TR>
    <TR bgcolor="#B6D5FA">
      <td bgcolor="#FFFFFF"><font face="Tahoma" size="1"><b></b></font></td>
      <TD height="21"  bgcolor="#FFFFFF" class="third"><b><font size="2" face="Tahoma">Minus or subtract </font></b></TD>
    </TR>
    <TR bgcolor="#FFFFFF">
      <TD height="36"><font class="sixth">&nbsp;C8&nbsp;</font> <b><font face="Tahoma" size="2"><br>
        </font></b></TD>
      <TD height="36"><b><font face="Tahoma" size="2">A</font></b></TD>
      <TD height="36">
        <div align="center"><font face="Tahoma" size="2"><b>C8</b></font></div>
      </TD>
      <TD height="36">
        <input name="C8" class="fourth" onBlur="MM_validateForm('C8','','NisNum');return document.MM_returnValue" size=12 maxlength="12">
      </TD>
    </TR>
    <TR bgcolor="#FFFFFF">
      <TD><font class="sixth">&nbsp;C9&nbsp;</font> <b></b></TD>
      <TD><b><font face="Tahoma" size="2">B</font></b></TD>
      <TD>
        <div align="center"><font face="Tahoma" size="2"><b>C9</b></font></div>
      </TD>
      <TD>
        <input name="C9" class="fourth" onBlur="MM_validateForm('C9','','NisNum');return document.MM_returnValue" size=12 maxlength="12">
      </TD>
    </TR>
    <TR bgcolor="#FFFFFF">
      <TD><font class="sixth">&nbsp;C10&nbsp;</font> <b></b></TD>
      <TD><b><font face="Tahoma" size="2">C</font></b></TD>
      <TD>
        <div align="center"><font face="Tahoma" size="2"><b>C10</b></font></div>
      </TD>
      <TD>
        <input name="C10" class="fourth" onBlur="MM_validateForm('C10','','NinRange0:20000');return document.MM_returnValue" size=12 maxlength="12">
      </TD>
    </TR>
    <TR bgcolor="#FFFFFF">
      <TD><font class="sixth">&nbsp;C11&nbsp;</font> <b></b></TD>
      <TD><b><font face="Tahoma" size="2">D</font></b></TD>
      <TD>
        <div align="center"><font face="Tahoma" size="2"><b>C11</b></font></div>
      </TD>
      <TD>
        <input name="C11" class="fourth" onBlur="MM_validateForm('C11','','NisNum');return document.MM_returnValue" size=12 maxlength="12">
      </TD>
    </TR>
    <TR bgcolor="#FFFFFF">
      <TD><font class="sixth">&nbsp;C12&nbsp;</font> <b></b></TD>
      <TD><b><font face="Tahoma" size="2">E</font></b></TD>
      <TD>
        <div align="center"><b><font face="Tahoma" size="2">C12</font></b></div>
      </TD>
      <TD>
        <input name="C12" class="fourth" onBlur="MM_validateForm('C12','','NisNum','C12','','NinRange0:20000');return document.MM_returnValue" size=12 maxlength="12">
      </TD>
    </TR>
    <TR bgcolor="#FFFFFF">
      <TD><font class="sixth">&nbsp;C13&nbsp;</font> <b></b></TD>
      <TD><b><font face="Tahoma" size="2">F</font></b></TD>
      <TD>
        <div align="center"><b><font face="Tahoma" size="2">C13</font></b></div>
      </TD>
      <TD>
        <input name="C13" class="fourth" onBlur="MM_validateForm('C13','','NisNum');return document.MM_returnValue" size=12 maxlength="12">
      </TD>
    </TR>
    <TR bgcolor="#94C6F8">
      <TD bgcolor="#94C6F8" class="third"><font class="sixth">&nbsp;C14&nbsp;</font>
        <b></b></TD>
      <TD bgcolor="#94C6F8" class="third"><b><font size="2" face="Tahoma">Total (c8+c9+c10+c11+c12=c14)</font></b></TD>
      <TD class="third">
        <div align="center"><b><font face="Tahoma" size="2">C14</font></b></div>
      </TD>
      <TD class="third">
        <input name="C14" type="text" class="fourth" onBlur="KW_calcForm('C14',1,-1,'#C8','+','#C9','+','#C10','+','#C11','+','#C12','+','#C13')" size=12 maxlength="12" readonly="true">
      </TD>
    </TR>
    <TR bgcolor="#FFFFFF">
      <TD class="fifth"><font class="sixth">&nbsp;C15&nbsp;</font> <b></b></TD>
      <TD class="fifth"><b><font size="2" face="Tahoma">G</font></b></TD>
      <TD>
        <div align="center"><b><font face="Tahoma" size="2">C15</font></b></div>
      </TD>
      <TD>
        <input name="C15" class="fourth" onBlur="MM_validateForm('C15','','NisNum');return document.MM_returnValue" size=12 maxlength="12">
      </TD>
    </TR>
    <TR bgcolor="#94C6F8">
      <TD class="third"><font class="sixth">&nbsp;C16&nbsp;</font> <b></b></TD>
      <TD class="third"><b><font size="2" face="Tahoma">Result (C7-C14-C15=C16)</font></b></TD>
      <TD class="third">
        <div align="center"><b><font face="Tahoma" size="2">C16</font></b></div>
      </TD>
      <TD class="third">
        <input name="C16" type="text" class="fourth" onBlur="KW_calcForm('C16',1,-1,'#pendapatanagregat','-','#C14','-','#C15')" size=12 maxlength="12" readonly="true">
     
       </TD>
    </TR>
  </TABLE>
  <p>&nbsp;</p>
  <p><br>
    <font face="Verdana, Arial, Helvetica, sans-serif" color=Gray size=1><br>
  </font> </p>
</FORM>

</BODY>

</HTML>
0
 
s34nCommented:
why so much code?

      if (document.frmname.textfield.value < 0)
            document.frmname.textfield.value = 0;


 just test the textfield after all calculations have taken place to see if it's less than zero.
0
 
inzhagiAuthor Commented:
Somehow i managed to understand ur coding with mine..thanks...where r u from?Malaysia or other country?thanks ok...
0

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now