Ejemplos en Javascript

Conversor financiero

Conversor

<HTML>
<HEAD>

<TITLE>Ejemplos Javascript: ejemplo pr???¡ctico </TITLE>

<!-- Cut-N-Paste JavaScript from ISN Toolbox
     Copyright 1996, Infohiway, Inc.  Restricted use is hereby
     granted (commercial and personal OK) so long as this code
     is not *directly* sold and the copyright notice is buried
     somewhere deep in your HTML document.  A link to our site
     http://www.infohiway.com is always appreciated of course,
     but is absolutely and positively not necessary. ;-)   -->
<SCRIPT LANGUAGE="JavaScript">
<!--Hide JavaScript from Java-Impaired Browsers
function test_it(entry) {
 if (entry.value!=null && entry.value.length!=0) {
  entry.value=""+ eval(entry.value);
  }
 computeForm(entry.form);
 }

function computeForm(form) {
 if ((form.months.value==null || form.months.value.length==0) ||
    (form.rate.value==null || form.rate.value.length==0) ||
    (form.financed.value == null || form.financed.value.length==0)) {
   return;
   }
 if (!alrt_msg(form.months,1,480,"Your Number of Payments") ||
    !alrt_msg(form.rate,.001,99,"Your Interest Rate") ||
    !alrt_msg(form.financed,100,10000000,"Your Principal Amount")) {
   form.payment.value="A value out of range - Click Reset";
   return;
    }
 var i=form.rate.value;
 ffv=0;
 ffv+=form.financed.value;
 fmv=0;
 fmv+=form.months.value;
 if (i > 1.0) {
 // Hack to mostly correct floating point/binary conversion error
  i=(i/100.0)+.00001;
  var fmt="";
  fmt+=i;
  fmt=fmt.substring(0,6)
  form.rate.value=fmt;
  }
 i/=12;
 var isn=1;
 for (var j=0;j<form.months.value;j++)
  isn=isn*(1+i);
  form.payment.value=(form.financed.value*isn*i)/(isn-1);
  fpv=0;
  fpv+=form.payment.value;
  var fmt="";
  var add=9;
  fmt+=form.payment.value;
  for (var i=0;i<fmt.length;i++) {
   if (fmt.charAt(i)==".") {
    add=i+3;
    i=fmt.length;
    }
   }
  fmt=fmt.substring(0,add);
  fcalc=((fmv*fpv)-ffv);
  var fmtb="";
  var add=9;
  fmtb+=fcalc;
  for (var i=0;i<fmtb.length;i++) {
   if (fmtb.charAt(i)==".") {
    add=i+3;
    i=fmtb.length;
    }
   }
  fmtb=fmtb.substring(0,add);
  form.payment.value="   $"+fmt+"              $"+fmtb;
 }
function reset_it(form) {
 form.months.value="";
 form.rate.value="";
 form.financed.value="";
 form.payment.value="";
 }

function alrt_msg(entry,low,high,prompt) {
 prompt="You couldn't know. "+prompt
 +" entry has unacceptable stuff: "+entry.value;
 var scratch=entry.value;
 for (var i=0;i<scratch.length;i++) {
  var letter=scratch.substring(i,i+1);
  if ((letter<"0" || "9"<letter) && letter!='.') {
   alert(prompt);
   return false;
   }
    }
 var errtst=parseFloat(scratch)
 if (errtst<low || high<errtst) {
  alert("I'm sorry. "+prompt+ " is not in the range"
  +" from "+low+" to "+high+"!");
  return false;
  }
 entry.value=scratch;
 return true;
 }
//-->
</SCRIPT>


</HEAD>

<BODY bgcolor="white">

<CENTER>
<FORM METHOD=POST>
<TABLE WIDTH=484 BORDER=2>
<TR>
<TD COLSPAN=3 VALIGN=TOP ALIGN=CENTER>
  <B>Simply Complete These Three Columns:</B></TD>
<TD VALIGN=TOP ALIGN=CENTER><B>See Your Payment Here</B></TD>
<TD VALIGN=TOP ALIGN=CENTER><B>See Your Interest Cost  Here</B></TD></TR>
<TR>
<TD ALIGN=CENTER>Number of<BR>Monthly<BR>Payments</TD>
<TD ALIGN=CENTER>Simple<BR>Interest<BR>Rate</TD>
<TD ALIGN=CENTER>Principal<BR>Amount<BR>of Loan</TD>
<TD ALIGN=CENTER>Your<BR>Monthly<BR>Payment<BR>Will Be</TD>
<TD ALIGN=CENTER>Your<BR>Total<BR>Interest Cost<BR>Will Be</TD>
</TR>
<TR>
<TD ALIGN=CENTER>
  <INPUT TYPE=TEXT NAME="months" SIZE=5 onChange=test_it(this)> </TD>
<TD ALIGN=CENTER>
  <INPUT TYPE=TEXT NAME="rate" SIZE=6 onChange=test_it(this)></TD>
<TD ALIGN=CENTER>
  $<INPUT TYPE=TEXT NAME="financed" SIZE=9 onChange=test_it(this)></TD>
<TD COLSPAN=2 ALIGN=CENTER>
  <INPUT TYPE=TEXT NAME="payment" SIZE=40 onChange=test_it(this)></TD></TR>
<TR>
<TD COLSPAN=2 ALIGN=CENTER>
  <INPUT TYPE="reset" VALUE="Click Here to Reset" onClick=reset_it(this.form)></TD>
<TD COLSPAN=3 ALIGN=CENTER>
  <INPUT TYPE="button" VALUE="Click Here to Compute Payment and Cost" onClick=computeForm(this.form)></TD>
</TR>
</TABLE>
</CENTER>


</body>
</html>

Conversores