?
Solved

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

Posted on 2005-03-23
5
Medium Priority
?
230 Views
Last Modified: 2008-03-03
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
Comment
Question by:inzhagi
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 8

Accepted Solution

by:
RozanaZ earned 400 total points
ID: 13619465
<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
 

Author Comment

by:inzhagi
ID: 13619680
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
 
LVL 8

Expert Comment

by:RozanaZ
ID: 13619714
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
 
LVL 1

Expert Comment

by:s34n
ID: 13622711
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
 

Author Comment

by:inzhagi
ID: 13627681
Somehow i managed to understand ur coding with mine..thanks...where r u from?Malaysia or other country?thanks ok...
0

Featured Post

Give Your Engineering Team a Productivity Boost

Learn why container technology is so powerful and how it can provide your team with productivity gains and other benefits.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

FAQ pages provide a simple way for you to supply and for customers to find answers to the most common questions about your company. Here are six reasons why your company website should have a FAQ page
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
The viewer will get a basic understanding of what section 508 compliance can entail, learn about skip navigation links, alt text, transcripts, and font size controls.
Suggested Courses

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question