Javascript function says it is undefined

everything I wrote to calculate many things,

so i put the value of my vars into hidden type input, so we have this code:

 <input type="hidden" id="p1" value="5000.00">
 <input type="hidden" id="p2" value="5000.01">
 <input type="hidden" id="p3" value="8000.00">
 <input type="hidden" id="p4" value="8000.01">
 <input type="hidden" id="t1" value="15.0">
 <input type="hidden" id="t2" value="12.0">
 <input type="hidden" id="t3" value="6.0">
 <input type="hidden" id="versement" value="12554.35">
 <input type="hidden" id="type" value="d">

      

Also, I have the following code, first enter to write down the amount to be calculated:

and the function on top:

therefore we have:

 <script language="text/javascript">
 function hono(p1,p2,p3,p4,t1,t2,t3,type,versement,montantacompte)
 {
     var p1             = document.getElementById("p1").value;
     var p2             = document.getElementById("p2").value;
     var p3             = document.getElementById("p3").value;
     var p4             = document.getElementById("p4").value;
     var t1             = document.getElementById("t1").value;
     var t2             = document.getElementById("t2").value;
     var t3             = document.getElementById("t3").value;
     var type           = document.getElementById("type").value;    
     var versement      = document.getElementById("versement").value;
     var montantacompte = document.getElementById("montantacompte").value;

     if (type== "d")
        {
            if(versement== 0 && montantacompte <= p1)
            {
                reste1= montantacompte;
                pc= t1/100;
                taux1= pc+1;
                h1=((reste1*taux1)+reste1);
                honoraires=h1;
                document.getElementById('taux-1').value=taux1;
                document.getElementById('palier1').value=h1;
                document.getElementById('sommehonoraires').value=honoraires;
            }
            else if(versement < p1 && (versement + acompte) <= p1)
            {
                reste1= montantacompte;
                pc= t1/100;
                taux1= pc+1;
                h1= (reste1*taux1)-reste1;
                honoraires= h1;
                document.getElementById('taux-1').value=taux1;
                document.getElementById('palier1').value=h1;
                document.getElementById('sommehonoraires').value=honoraires;
            }
            else if(versement <= p1 && (versement+montantacompte)>= p2 && (versement+montantacompte)<=p3)
            {
                reste1=p1-versement;
                pc=t1/100;
                taux1=pc+1;
                h1=(reste1*taux1)-reste1;
                reste2=montantacompte-reste1;
                pc2=t2/100;
                taux2=pc2+1;
                h2=(reste2*taux2)-reste2;
                honoraires=h1+h2;
                document.getElementById('taux-1').value=taux1;
                document.getElementById('palier1').value=h1;
                document.getElementById('taux-2').value=taux2;
                document.getElementById('palier-2').value=h2;
                document.getElementById('sommehonoraires').value=honoraires;
            }
            else if (versement==0 && montantacompte>=p2 && montantacompte <=p3)
            {
                reste2=montantacompte-p1;
                reste1=p1;
                pc=(t1/100);
                taux1=pc+1;
                h1=((reste1*taux1)-reste1);
                pc2=(t2/100);
                taux2=pc2+1;
                h2=((reste2*taux2)-reste2);
                honoraires=(h1+h2);
                document.getElementById('taux-1').value=taux1;
                document.getElementById('palier1').value=h1;
                document.getElementById('taux-2').value=taux2;
                document.getElementById('palier2').value=h2;
                document.getElementById('sommehonoraires').value=honoraires;
            }
            else if(versement<=p3 && versement>=p2 && (versement+montantacompte)>=p2 && (versement+montantacompte)<=$3)
            {
            reste1=montantacompte;
            pc=($2/100);
            taux1=pc+1;
            h1=((reste1*taux1)-reste1);
            honoraires=h1;  
            document.getElementById('taux-1').value=taux1;
            document.getElementById('palier1').value=h1;
            document.getElementById('sommehonoraires').value=honoraires;
            }
            else if(versement>=p2 && versement<=p3 && (versement+montantacompte)>=p4)
            {
            reste1=p4-versement;
            pc=(t2/100);
            taux2=pc+1;
            h2=((reste1*taux2)-reste1);
            reste2=montantacompte-reste1;
            pc2=(t3/100);
            taux3=pc2+1;
            h3=((reste2*taux3)-reste2);
            honoraires=(h2+h3);
            document.getElementById('taux-3').value=taux3;
            document.getElementById('palier3').value=h3;
            document.getElementById('taux-2').value=taux2;
            document.getElementById('palier2').value=h2;
            document.getElementById('sommehonoraires').value=honoraires;
        }
        else if(versement==0 && montantacompte>=p4)
        {
            reste1=p1;
            reste2=p3-p2;
            pc=(t1/100);
            taux1=pc+1;
            h1=((reste1*taux1)-reste1);
            pc2=(t2/100);
            taux2=pc2+1;
            h2=((reste2*taux2)-reste2);
            reste3=(montantacompte-reste1-reste2);
            pc3=(t3/100);
            taux3=pc3+1;
            h3=((reste3*$taux3)-reste3);
            honoraires=(h1+h2+h3);
            document.getElementById('taux-1').value=taux1;
            document.getElementById('palier1').value=h1;
            document.getElementById('taux-3').value=taux3;
            document.getElementById('palier3').value=h3;
            document.getElementById('taux-2').value=taux2;
            document.getElementById('palier2').value=h2;
            document.getElementById('sommehonoraires').value=honoraires;
        }
    else if(versement>=p4)
        {
            reste3=montantacompte;
            pc3=($3/100);
            taux3=pc3+1;
            h3=((reste3*taux3)-reste3);
            honoraires=(h3);
            document.getElementById('taux-3').value=taux3;
            document.getElementById('palier3').value=h3;
            document.getElementById('sommehonoraires').value=honoraires;
        }
    }
    if (type=="l")
    {
    pc1=(t1/100);
    taux1=pc1+1;
    honoraires=montantacompte*taux1;
    document.getElementById('taux-1').value=taux1;
    document.getElementById('palier1').value=h1;
    document.getElementById('sommehonoraires').value=honoraires;
    }
 }

 </script><input type="text" name="montantacompte" id="montantacompte" onKeyUp="hono(p1,p2,p3,p4,t1,t2,t3,type,versement,montantacompte)"  /> 

      

And in the console, it tells me that the function is undefined, or it is there because I wrote it ... Everything is in the body.

We have this in the console:

Unprepared ReferenceError: hono not defined test.php: 166 OnKeyUp

and line 166 is the text of the input after the function.

sorry for my bad english,

If you need further guidance, just ask me.

0


source to share


2 answers


language="text/javascript"

is not correct, it should be language="JavaScript"

, but old / deprecated / deprecated / deprecated, so use type="text/javascript"

instead



+2


source


At first glance, I noticed that you have the wrong script attributes.

 <script language="text/javascript">

      



it should be:

 <script type="text/javascript">

      

0


source







All Articles