mercredi 15 juin 2016

dynamic textbox value multiplying while keyup function in jquery

Here multiple text box available...I need to do multiply day rate and no of day allowed while keyup function in jquery. I have tried to multiply the two value and the output will show in another equal textbox. The output value does not show in that equal text box.

PHP code

<?php
    $qry = mysql_query("SELECT * FROM vefm_ts_engr_details WHERE job_number='" . $jobno . "'", $dbcon);
    $norows = mysql_num_rows($qry);
    $i = 1;
    while ($srow = mysql_fetch_array($qry)) {

        $isql = mysql_query("SELECT * FROM vefm_engineer_details WHERE ecode='" . $srow['ecode_id'] . "'", $dbcon);
        $ires = mysql_fetch_array($isql);

        ?>
        <div class="row">
            <div class="form-group col-sm-2" align="right">
                <label>Day Rate of </label> 
                <label class="fonts" style="color:purple"><?php echo $ires['engr_name']; ?></label>
            </div>
            <div class="form-group col-sm-3" align="left">
                <input type="text" id="dayrate<?php echo $i ;?>" name="dayrate[]" class="form-control" value="">
                <input type="hidden" id="allowed_days<?php echo $i ;?>" name="allowed_days[]" class="form-control" value="<?php echo $srow['allowed_days'];?>">
                <span id="errmsg1" style="color:red;"></span>
            </div>
            <div class="form-group col-sm-2" align="left">
                <label class="fonts"><?php echo $srow['allowed_days']; ?></label> 
                <label> (NO of days allowed)</label>
            </div>
            <div class="form-group col-sm-3" align="left">
                <input type="text" id="amt<?php echo $i ;?>" name="amt" class="form-control" value="" >
            </div>
        </div>
        <?php
        $i++;
    }
?>

JQuery code:

var rowCount = $('#totalrows').val();
var i;
alert(rowCount);

for (i = 1; i <= rowCount; i++) {            
    var allowday = $('#allowed_days' + i).val();
    // alert(allowday);                                                      

    $('#dayrate' + i).keypress(function(e) {
        // alert(allowday);
        var x = 1;
        if (x<=i) {
            $('#amt'+x).val((String.fromCharCode(e.which))*allowday); 
            x++;     
        }   

    });
}

this is the output screen

Aucun commentaire:

Enregistrer un commentaire