Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

Archive

Our old forums are still available as a read-only archive.

Moderators: martimiz, Sean, biapar, Willr, Ingo, simon_w

creditcalculator javascript in Page.ss


Reply

3 Posts   1166 Views

Avatar
Macello

22 October 2008 at 1:41am Community Member, 37 Posts

Hi i added a script to my Page.ss, the script works well in a html, but not in my Page.ss.
Hope somebody can help me, this is my Page.ss:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" >
<head>

<% base_tag %>
<link rel="stylesheet" type="text/css" href="../css/layout.css" />
<link rel="stylesheet" type="text/css" href="../css/typography.css" />
<link rel="stylesheet" type="text/css" href="../css/form.css" />
<title>Swiss Finance Scout - $Title</title>
<script language="javascript" type="text/javascript">

var amount, apr, n, payment, npy, tablebuilt=false;

function calculate(){
var d=document.f;
amount=d.amount.value;
apr=d.apr.value;
n=d.n.value;
npy=d.npy.value;
if( (amount!='') && (n!='') && (apr!='') && (npy!='') ){
tmp=Math.pow((1+(apr/100/npy)), (n*npy));
payment=(amount*tmp*(apr/100/npy))/(tmp-1);
if((!isNaN(payment))&&(payment!=Number.POSITIVE_INFINITY)&&(payment!=Number.NEGATIVE_INFINITY)){
d.payment.value=round(payment);
d.totpaid.value=round(payment*n*npy);
d.intpaid.value=round((payment*n*npy)-amount);
}else alert('Error: \Sie haben eine Falsch Eingabe gemacht. \Geben Sie kein "Komma""," im Eingabefeld an. \Alternativ müssen Sie einen "Punkt""." setzen.');
}else alert('Error:\Tragen Sie bitte in alle Felder die Kredit-Daten ein, zum errechnen und erstellen Ihrer Kalkulation.');
}

function round(val){
tmp=Math.round(val*100)/100+'';
if(tmp.indexOf('.')==-1)tmp+='.00';
else if(tmp.length-tmp.indexOf('.')==2)tmp+='0';
return tmp;
}

function resetall(){
var d=document.f;
d.amount.value='';
d.apr.value='';
d.n.value='';
d.npy.value=12;
d.payment.value='';
d.totpaid.value='';
d.intpaid.value='';
d.amount.focus();
}

function buildtable(){
tablebuilt=true;
txt='<html><head><title>Kredit und Ratenzahlungs Rechner</title></head><body bgcolor="#00436e"><center><form>';
txt+='<input type="button" value="Fenster Schließen" onClick="self.close()"><br><br>';
txt+='<table bgcolor="white" border="1" cellpadding="4">';
txt+='<tr><td align="center">Anzahl<br>Raten</td><td align="center">Rate<br>monatlich</td><td align="center">Zins</td><td align="center">Netto</td><td align="center">Balance</td></tr>';
amount=eval(amount);
for(i=1;i<=n*npy;i++){
tbldata='<td bgcolor="'+((i%2!=0) ? 'lightblue' : 'white')+'" align="right">';
interest=amount*apr/npy/100;
amount+=interest;
principle=payment-interest;
amount-=payment;
txt+='<tr>'+tbldata+i+':</td>'+tbldata+round(payment)+'</td>'+tbldata+round(interest)+'</td>'+tbldata+round(principle)+'</td>'+tbldata+round(amount)+'</td></tr>';
}
txt+='</table><br><br><input type="button" value="Fenster Schließen" onClick="self.close()"></center></form></body></html>';
var psch=window.open('', 'viewsch' ,'top=0,left=0,toolbar=no,scrollbars=yes,resizable=yes,width=500,height=450,menubar=no,status=no');
psch.document.write(txt);
}

window.onload=function(){
document.f.amount.focus();
}

</script>
<meta name="author" content="WG-Softwareentertainments, Werner Gerber">
<meta name="description" content="Generator zum errechnen von Kreditverpflichtung sowie Laufzeit, Ratenhöhe, Zinsbelastung und erstellen eines Rückzahlungs und Ratenplanes">
<meta name="keywords" content="rate, kredit, zins, belastung, kostenlos, umsonst, rückzahlungsplan, ratenplan, geld, auto, motorrad, haus, immobilie, finanzieren">
<meta name="robots" content="index fallow">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<script type="text/javascript">
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</script>
<script type="text/javascript">
var pageTracker = _gat._getTracker("UA-5504189-2");
pageTracker._trackPageview();
</script>
<body>
<div id="container">
   <div id="banner" ><div id="slogan" ><h4>...Ihr unabhängiger
    <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Finanzpartner</h4></div>
    <img src="/mysite/images/logo.png" height="100" width="175" alt="Swiss Finance Scout" /></div>
   <div id="container2">
      <div id="Menu1">
         <ul>
          <% control Menu(1) %>
          <li><a href="$Link" title="Go to the &quot;{$Title}&quot; page">$MenuTitle</a></li>
          <% end_control %>
         </ul>
      </div>
      <div id="left">
         <h5>$Title</h5>
         <% if Menu(2) %>
             <ul id="nav">
             <% control Menu(2) %>
             <li class="$LinkingMode"><a href="$Link" title="Go to the &quot;{$Title}&quot; page">â–¸ $MenuTitle</a>
             <% if Children %>
                <% control Children %>
                <ul>
                <li class="$LinkingMode $FirstLast"><a href="$Link">â–¹ $MenuTitle</a></li>
                  </ul>
                  <% end_control %>
                  <% end_if %></li>
             <% end_control %>
             </ul>
         <% end_if %>
         </div>
      <div id="right">
         $SearchForm
<div id="Kreditre">
<h1>Kredit-Rechner</h1>
<form name="f">
Kreditbetrag:<br><input type="text" name="amount" class="text nolabel" size="10">&nbsp;CHF<br>
Zinssatz:<br><input type="text" name="apr" class="text nolabel" size="5" value="10.9"><br>
Laufzeit in Jahren:<br><input type="text" name="n" class="text nolabel" size="5"><br>
Zahlungen pro Jahr:<br><input type="text" name="npy" class="text nolabel" size="5" value="12"><br><br>
<input type="button" value="Berechnen" onClick="calculate()">&nbsp;&nbsp;<input type="button" value="Reset" onClick="resetall()"><br><br>
Monatl. Raten inkl Zinsen:<br><input type="text" size="10" name="payment" class="text nolabel"><br>
Kreditbelastung inkl. Zinsen:<br><input type="text" size="10" name="totpaid" class="text nolabel"><br>
Zinsbelastung:<br><input type="text" size="10" name="intpaid" class="text nolabel"><br><br>
<input type="button" value="Zahlungsplan" onClick="buildtable()"><br><br>
</form>
</div>
         <% control Page(RightSide) %>
         $Content <br />
         <% end_control %>
      </div>
      <div id="content">
            <div id="Content" class="typography">
            <% if Level(2) %>
               <div class="breadcrumbs">
            $Breadcrumbs
               </div>
            <% end_if %>
            $Content
            $Form
            </div>
      </div>
   </div>
<div id="footer">
<div id="login"><h3><a href="../../admin/">login</a></h3></div>
<h1><a href="http://www.studio83.ch" target="_blank"><img src="../mysite/images/design8.png" alt="83" width="16px" height="25px" border="0" longdesc="http://www.studio83.ch" /></a></h1>
</div>
<div class="copyright">
design © 2008 by <a href="http://www.studio83.ch" target="_blank">Studio83.ch</a>
</div>
</div>
</body>
</html>

Thanks in avdvance

Marcello

Avatar
Willr

22 October 2008 at 10:41pm Forum Moderator, 5511 Posts

Do you happen to have a <? xml declaration at the top of the file like the default theme? This will send the template as xml which doesn't have support for document.write(); which you use in your javascript.. If thats not the issue maybe you want to post a link to it online and we can try and debug via the live script

Avatar
Macello

25 October 2008 at 12:38am Community Member, 37 Posts

Yes could be a solution, but because of the sites online and live i removed the script.
At the moment its not that important, but still i'm happy to get ideas!