I created a small form witch is supposed to automatically calculate the price via onKeyUp=()
and in explorer all is working fine but in explorer the script goes exactly untill the following line.
document.getElementById(naam+"txt").value='';
after that the script quits no error it just stops.
I'll try to make the code as short as possible
Expand|Select|Wrap|Line Numbers
- <html>
- <head>
- <title>Index pagina</title>
- <script type="text/javascript">
- //small script to see if it is a number or not
- function is_int(value){
- if((parseFloat(value) == parseInt(value)) && !isNaN(value)){
- return true;
- } else {
- return false;
- }
- }
- //calculate the total price
- function totaal()
- {
- var prijs= 0;
- <?php
- $X= array("spagGR","* Spaghetti","-groot:",7.5);
- ?>
- prijs = prijs+(<?php echo $X[3];?>* document.getElementById("<?php echo $X[0]; ?>txt").value);
- document.getElementById("totaal").innerHTML=prijs;
- return;
- }
- function berekenen(str, prijs, naam)
- {
- //alert(str+prijs+naam);
- //check if it is filled in
- if (str.length==0)
- {
- document.getElementById(naam).innerHTML=" ";
- totaal()
- return;
- }
- //check if it is a number
- if (is_int(str)==false)
- {
- alert("Gelieve een cijfer in te vullen.");
- document.getElementById(naam).innerHTML=" ";
- document.getElementById(naam+"txt").value='';
- totaal()
- return;
- }
- //calculate the price
- document.getElementById(naam).innerHTML=str*prijs;
- totaal()
- return;
- }
- </script>
- </head>
- <body>
- <FORM METHOD="post" TARGET="_self" ACTION="pastabasta.php?p=3">
- <table border=0 cellpadding=0 cellspacing=0>
- <?php
- $X= array("spagGR","* Spaghetti","-groot:",7.5);
- ?>
- <tr>
- <td><?php echo $X[1];?></td>
- <td><?php echo $X[2];?></td>
- <td><?php echo "€ ".$X[3]; ?></td>
- <td class="puntjesTD">-><INPUT class="puntjes" maxlength="2" NAME="<?php echo $X[0];?>txt" SIZE="1" onKeyUp="berekenen(this.value,<?php echo $X[3]; ?>,'<?php echo $X[0];?>')" ></td>
- <td>X<?php echo $X[3]."=";?></td><td><em id="<?php echo $X[0];?>" name="<?php echo $X[0];?>" class="puntjes"> </em></td></tr><tr>
- <td colspan="5" align="right">Totaal bedrag: </td><td><em id="totaal" name="totaal" class="puntjes" > </em></td>
- </tr>
- </table>
- </FORM>
- </body>
- </html>
I have also tried replacing getElementById with document.forms['name_of_form'].name_of_input.value
but I still get the same issue...
any idea is welcome!
normally you can check the result on http://joop.vazant.be/www/chiro/pastabasta.php
and the send option isn't written yet so feel free to test what you like :)
the best place to change something for testing is right after the second alert.
Expand|Select|Wrap|Line Numbers
- if (is_int(str)==false)
- {
- alert("Gelieve een cijfer in te vullen.");
- document.getElementById(naam).innerHTML=" ";
- document.getElementById(naam+"txt").value='';