Why doesn't work on first keypress

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Ghosty
    New Member
    • Dec 2010
    • 2

    #1

    Why doesn't work on first keypress

    I have this code i got it from this forum and modified it a bit but i'm having a problem:
    when i type the first number in the textbox id="qty1" it doesn't modify the other textbox.
    for example type 0.68 to see what i mean.
    it gives 4.80 when it should give 5.44
    meaning it does 8x0.6

    thnx,

    Code:
     
    <?php
    echo '<html xmlns="http://www.w3.org/1999/xhtml">
     
    <head>
    <script type="text/javascript">
     
    function calct1(unId, quId, stId) {
        var un1=document.getElementById(unId).value;
        var qn1=document.getElementById(quId).value;
        var x1=parseFloat(un1);
        var y1=parseFloat(qn1);
        var z1=(x1*y1);
        var sb1=z1.toFixed(2);
        document.getElementById(stId).value=sb1;
    }
     
    </script>
    </head>
    <body>';
    echo'    <input type="text" id="unit1" size="6" maxlength="6" value="8.00" readonly="readonly">';
    ?>
        <input type="text" id="qty1" size="6" maxlength="6" value="0" onkeypress="calct1('unit1', 'qty1', 'sub1')">
    
        <input type="submit" value="Calc" onClick="">
    <?php
    echo'
        <input type="text" id="sub1" size="6" maxlength="6" value="0.00">
        <br/><br/>
        <input type="text" id="unit2" size="6" maxlength="6" value="8.00" readonly="readonly">
        <input type="text" id="qty2" size="6" maxlength="6" value=0 onClick="(this.value="")">
        <input type="submit" value="Calc" onClick="calct1("unit2", "qty2", "sub2")">
        <input type="text" id="sub2" size="6" maxlength="6" value="0.00">
    </body>
    </html>';
  • Logic Ali
    New Member
    • Jul 2010
    • 16

    #2
    Use the onkeyup event instead.

    Comment

    • Ghosty
      New Member
      • Dec 2010
      • 2

      #3
      Tjnx for the help. :)

      Comment

      Working...