noalyss  Version-6.7.2
 All Data Structures Namespaces Files Functions Variables Enumerations
calc.js
Go to the documentation of this file.
00001 /*
00002  *   This file is part of NOALYSS.
00003  *
00004  *   NOALYSS is free software; you can redistribute it and/or modify
00005  *   it under the terms of the GNU General Public License as published by
00006  *   the Free Software Foundation; either version 2 of the License, or
00007  *   (at your option) any later version.
00008  *
00009  *   NOALYSS is distributed in the hope that it will be useful,
00010  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  *   GNU General Public License for more details.
00013  *
00014  *   You should have received a copy of the GNU General Public License
00015  *   along with NOALYSS; if not, write to the Free Software
00016  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00017 */
00018 /* $Revision$ */
00019 
00020 // Copyright Author Dany De Bontridder danydb@aevalys.eu
00021 
00022 /*! \file
00023  * \brief This file show a little online calculator, in the caller
00024  *        the span id result, listing, the id form calc_line and the
00025  *       
00026  *
00027  */
00028 var p_history="";
00029 var p_variable="";
00030 // add input
00031 function cal()
00032 {
00033     p_variable=this.document.getElementById('inp').value;
00034     if (p_variable.search(/^\s*$/) !=-1)
00035     {
00036         return;
00037     }
00038     try
00039     {
00040         Compute();
00041         p_variable=p_variable.replace(/ /g,"");
00042         p_variable=p_variable.replace(/\+/g,"+ ");
00043         p_variable=p_variable.replace(/-/g,"- ");
00044         p_variable=p_variable.replace(/\//g,"/ ");
00045 
00046         sub=eval(p_variable);
00047         var result=parseFloat(sub);
00048         result=Math.round(result*100)/100;
00049     }
00050     catch(exception)
00051     {
00052         alert("Mauvaise formule\n"+p_variable);
00053         return false;
00054     }
00055     p_history=p_history+'<hr>'+p_variable;
00056     p_history+="="+result.toString();
00057     var str_sub="<hr><p> Total :"+p_variable+" = "+result.toString()+"</p>";
00058     this.document.getElementById("sub_total").innerHTML=str_sub;
00059     this.document.getElementById("listing").innerHTML=p_history;
00060     this.document.getElementById('inp').value="";
00061 }
00062 // Clean
00063 //
00064 function Clean()
00065 {
00066     this.document.getElementById('listing').innerHTML="";
00067     this.document.getElementById('result').innerHTML="";
00068     this.document.getElementById('sub_total').innerHTML="";
00069     this.document.getElementById('inp').value="";
00070     this.document.getElementById('inp').focus();
00071 
00072 }
00073 
00074 function Compute()
00075 {
00076     var tot=0;
00077     var ret="";
00078 
00079     this.document.getElementById('inp').value="";
00080     this.document.getElementById('inp').focus();
00081 }
 All Data Structures Namespaces Files Functions Variables Enumerations