I'm trying to pass the ac_no contained in my database table to a form that's displayed within a Bootstrap Modal upon clicking a button. My code is as follows.

<?php
            $mydata = mysql_query("SELECT * FROM slabpay WHERE ac_no='$ac_no'");
                        while($record = mysql_fetch_array($mydata)) 
             { 
             $id=$record['id'];
                  ?>                    
                            <tr class='fired' id='<?php echo $record['id']; ?>'>
                                <td class="center"><?php echo $record['install_no'] ?></td>
                                <td class="center"><?php echo $record['install_amt'] ?></td>
                                <td class="center"><?php echo $record['install_date'] ?></td>
                                <td class="center"><?php echo $record['agent_name'] ?></td>
                                <td id="fired" class="center">
                                                                    <?php
                                                                    if($record['install_amt']=='000000')
                                                                    {
                                                                        ?>

<button class="btn btn-info" data-toggle="modal" data-target="#payAmt" data-id="<?php echo $row['ac_no']; ?>">
  <i class="halflings-icon white edit"></i>    
</button>                                                                        
                                                                    <?php
                                                                    }
                                                                    ?>
                                </td>
                            </tr>

                                                            <?php
            }
?> 

// Javascript Code

<script>
$(document).ready(function(){
       $("#fired").click(function(){
         $("#ac_no").val($(this).attr('data-id')); 
         $('#payAmt').modal('show');
       });
    }); 
</script>


// modal window code

<div id="payAmt" class="modal hide fade" tabindex="-1" role="dialog" aria-hidden="true">            
        <div class="modal-header">

                        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>

        </div>
        <div class="modal-body">

                        <input type="hidden" class="form-control" id="ac_no" name="ac_no" value="" />
                        <?php
                        $result = $_POST['ac_no'];
                        echo $result;
                        ?>
        </div>
        <div class="modal-footer">
            <a href="#" class="btn" data-dismiss="modal">Close</a>
            <a href="#" class="btn btn-primary">Save changes</a>
        </div>
    </div>

Hope you guys will figure out this problem. Thanks in advance

Member Avatar for diafol

Your ajax routine will work off the "save changes" button-link click won't it in the modal footer?

$('.model-footer a.btn-primary').click(function(){
    //run your ajax code here
});

thanks diafol

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.