Narayan Bhat
Narayan Bhat

Reputation: 21

php how to get dynamically created textbox for onblur function

I am fetching details from database and showing in same page,I have to update value on blur of weight column. My problem is onblur not working. Please look into the blur function code below,kindly help. :)

<!DOCTYPE html>
<html>
<head>
    <?php 
        include "dbconfig.php";
        include "yrsetup.php";      
        $ttable='lot'.$yr;
    ?>
    <style>

    </style>
 <script type="text/javascript" src="jquery-1.6.1.js"></script>
 <script>
    $(document).ready(function(){
        $("#tdate").change(function(){
        var tdate = $(this).val();
            $.post("lotno.php",
                     {
                         tdate: tdate
                     },
                     function(data,status){
                         $("#target-content").html(data);
                         //alert("Data: " + data + "\nStatus: " + status);
            });         
        });

        $("#target-content").change(function(){
        var tlotno = $(this).val();
        var tdate = $("#tdate").val();
//alert(tlotno);        
        $.post("getdet.php",
                     {
                         tlotno: tlotno,
                         tdate: tdate
                     },
                     function(data,status){
                         $("#gtdet").html(data);
                         //alert("Data: " + data + "\nStatus: " + status);
            });         
        });
///////////////////

////////////////////////////////
    $(".bweight").blur(function(){
    var text = $(this).val();
    alert(text);
/*  id = $(this).closest('.mob').attr('data-id');
            $.post("mobupdate.php",
                 {
                     id: id,
                     text: text
                 },
                 function(data,status){
                        // $("#target-content").html(data);
                        //  alert("Data: " + data + "\nStatus: " + status);
                 });            
 */ 
 });

});


</script> 

</head>
    <body>


enter code here

    <form>
            <table>
                <tr>
                    <td>
                        Select Date:<input type="date" id='tdate' name='tdate' >
                    </td>
                    <td>
                        Select A/P/C:
                            <select name='apcslct' class='apcslct'>
                                <option>A</option>      
                                <option>P</option>      
                                <option>C</option>                                      
                            </select>
                    </td>

                    <td>
                        Select LotNo:
                        <select id="target-content"></select>
                    </td>
                </tr>               
            </table>
            <div id="gtdet">

            </div>  
        </form>

    </body>
</html>



getdet.php

<?php 
    include "dbconfig.php";
    include "yrsetup.php";      
    $ttable='lot'.$yr;

    $tdate1=$_POST['tdate'];
    //$tdate1=date('d-m-Y');
    $tdate = date('Y-m-d', strtotime($tdate1));

    $tlotno=$_POST['tlotno'];

    //echo $tdate;
        $sql="SELECT lotno,asmsoc,$ttable.acno,CONCAT(assami.frst,' ',assami.send,' ',assami.thrd,' ',assami.vilg) AS ename,
        $ttable.sacno,sno,apcd,allcodes.name AS iname,nobgs,kqty,kore,$ttable.rate,purno,pur.`send` as purnm,nqty AS weight 
        FROM $ttable 
        LEFT JOIN assami ON assami.mrk IS NULL AND  $ttable.acno=assami.acno
        LEFT JOIN allcodes ON allcodes.sw='IT'  AND $ttable.`apcd`=allcodes.cd
        LEFT JOIN pur ON pur.mrk IS NULL AND $ttable.purno=pur.`acno`
        WHERE $ttable.mrk IS NULL AND  date1='$tdate' AND atoz='$tlotno' AND asmsoc='A' UNION ALL
        SELECT lotno,asmsoc,$ttable.acno,society.ename AS ename,
        $ttable.sacno,sno,apcd,allcodes.name AS iname,nobgs,kqty,kore,$ttable.rate,purno,pur.`send` as purnm,nqty AS weight 
        FROM $ttable 
        LEFT JOIN society ON society.mrk IS NULL AND  $ttable.acno=society.acno
        LEFT JOIN allcodes ON allcodes.sw='IT'  AND $ttable.`apcd`=allcodes.cd
        LEFT JOIN pur ON pur.mrk IS NULL AND $ttable.purno=pur.`acno`
        WHERE $ttable.mrk IS NULL AND  date1='$tdate' AND atoz='$tlotno' AND asmsoc='S' ORDER BY lotno ";

    $res=mysqli_query($mysqli,$sql);
    if($res == FALSE) {
       die(mysqli_error($mysqli)); // TODO: better error handling
    }else{
        //printf("Select returned %d rows.\n", $res->num_rows);
    }
    $row=mysqli_fetch_array($res);
?>
<table border="1px">
<tr>
    <th>
        LOtno
    </th>
    <th>
        A/S
    </th>
    <th>
        Acno
    </th>

    <th>
        Name
    </th>
    <th>
        SubNo
    </th>
    <th>
        Sno
    </th>
    <th>
        Icode
    </th>
    <th>
        Item
    </th>
    <th>
        Bags
    </th>
    <th>
        Kqty
    </th>
    <th>
        Kore
    </th>
    <th>
        Rate
    </th>
    <th>
        PCode
    </th>
    <th>
        PName
    </th>
    <th>
        Weight
    </th>

</tr>
<?php
    do{
?>
<tr>
    <td>
        <input type="text" disabled="disabled" name="lotno" class="lotno" value="<?php echo $row['lotno']; ?>" data-id="<?php echo $row['lotno'];?>" style="width:30PX" >
    </td>
    <td>
        <?php echo $row['asmsoc'];?>
    </td>
    <td>
        <?php echo $row['acno'];?>
    </td>
    <td>
        <?php echo $row['ename'];?>
    </td>
    <td>
        <?php echo $row['sacno'];?>     
    </td>
    <td>
        <?php echo $row['sno'];?>
    </td>
    <td>
        <?php echo $row['apcd'];?>
    </td>
    <td>
        <?php echo $row['iname'];?>
    </td>
    <td>
        <?php echo $row['nobgs'];?>
    </td>
    <td>
        <?php echo $row['kqty'];?>
    </td>
    <td>
        <?php echo $row['kore'];?>
    </td>
    <td>
        <?php echo $row['rate'];?>
    </td>
    <td>
        <?php echo $row['purno'];?>
    </td>
    <td>
        <?php echo $row['purnm'];?>
    </td>
        <?php if ($row['weight']>0){ ?>
            <td>
                <input type="number" class="bweight" value="<?php echo $row['weight'];?>" style="border:none;" onblur="blr(this);" >
            </td>
        <?php } else { ?>
        <td >
            <input type="number" class="bweight" style="border:none;" onblur="blr(this);">
        </td>
        <?php } ?>
    </td>   
    </td>
</tr>   
<?php
    }while ($row=mysqli_fetch_array($res)); 
?>  
</table>

Upvotes: 1

Views: 275

Answers (2)

Sanchit Gupta
Sanchit Gupta

Reputation: 3224

Try with Upgraded jQuery i.e jQuery 1.7+ jQuery On inside $(document).ready Or you can use live instead of on:

$("body").on("blur",".bweight",function(){
    var text = $(this).val();
    alert(text);
 });

Upvotes: 0

TurtleTread
TurtleTread

Reputation: 1314

You are using jQuery 1.6. The on() function is not available yet. Use live() instead : http://api.jquery.com/live/

Upvotes: 1

Related Questions