using javascript function in php while loop

前端 未结 2 1001
没有蜡笔的小新
没有蜡笔的小新 2021-01-29 08:12

I am trying to multiply values in two text boxes and place it on a third text box... Using javascript and php while loop with onclick event.....How to do that?? my code is

2条回答
  •  无人及你
    2021-01-29 09:03

    Try like this

    while($c=mysql_fetch_array($b)) {
    echo "
                //Let you want to pass id from DB
          ";
    

    or you can use

    onkeypress='multiply('.$c['id'].')'
    

    USE onkeypress instead of onclick() and in your script

    function multiply(id)
    {
    
       var textValue1 = document.getElementById('CLS'+id).value;
       var textValue2 = document.getElementById('rate'+id).value;
    
       document.getElementById('valuation'+id).value = textValue1 * textValue2;
    
    }
    

    And try to avoid mysql_* functions because they are depricated,instead use either mysqli_* functions or PDO statements

提交回复
热议问题