Capture values of HTML elements in a dynamic table

前端 未结 1 599
无人共我
无人共我 2021-01-27 09:54

I have the following dynamic table generated from database.

相关标签:
1条回答
  • 2021-01-27 10:35

    Correct Me If I am not wrong.. Here you want to get the all value from a form Right? on click of button submit? Why you are making this button href? Suppose we have 3 data into my $result and loops look like below

     <form method="post" action="">
    <tr>
           <td scope="row"></td>
           <input type ="text" name="sourece" value=1 />
                  <td>                         
                        <input type="number" class="form-control" id="shift1PinCount" name="shift1PinCount" placeholder="Pin Count" title="Please key in Pin Count for Shift 1" min=0>
                  </td>
    
                  <td>
                        <input type="text" class="form-control" id="shift1Oa" name="shift1Oa" value="1" disabled>
                  </td>
    
                  <td>
                        <input type="number" class="form-control" id="shift2PinCount" name="shift2PinCount" placeholder="Pin Count" title="Please key in Pin Count for Shift 2" min=0>
                  </td>
    
                  <td>
                        <input type="text" class="form-control" id="shift2Oa" name="shift2Oa" value="2" disabled>
                  </td>
    
                  <td>
                        <input type="number" class="form-control" id="shift3PinCount" name="shift3PinCount" placeholder="Pin Count" title="Please key in Pin Count for Shift 3" min=0>
                  </td>
    
                  <td>
                        <input type="text" class="form-control" id="shift3Oa" name="shift3Oa" value="3" disabled>
                  </td>
    
                  <td>
                        <input type="number" class="form-control" id="shift4PinCount" name="shift4PinCount" placeholder="Pin Count" title="Please key in Pin Count for Shift 4" min=0>
                  </td>
    
                  <td>
                        <input type="text" class="form-control" id="shift4Oa" name="shift4Oa" value="4" disabled>
                  </td>
    
                  <td><input class="form-control" type="date" id="shiftDate" name="shiftDate" value="<?=date("Y-m-d")?>"></td>
    
                  <td>
                    <input type="submit" class="btn btn-primary" name="savePcData" id="savePcData" value="savePcData">
                  </td> 
    </form>
    </tr>
    <form method="post" action="">
    <tr>
           <td scope="row"></td>
           <input type ="text" name="sourece" value=2 />
                  <td>                         
                        <input type="number" class="form-control" id="shift1PinCount" name="shift1PinCount" placeholder="Pin Count" title="Please key in Pin Count for Shift 1" min=0>
                  </td>
    
                  <td>
                        <input type="text" class="form-control" id="shift1Oa" name="shift1Oa" value="11" disabled>
                  </td>
    
                  <td>
                        <input type="number" class="form-control" id="shift2PinCount" name="shift2PinCount" placeholder="Pin Count" title="Please key in Pin Count for Shift 2" min=0>
                  </td>
    
                  <td>
                        <input type="text" class="form-control" id="shift2Oa" name="shift2Oa" value="22" disabled>
                  </td>
    
                  <td>
                        <input type="number" class="form-control" id="shift3PinCount" name="shift3PinCount" placeholder="Pin Count" title="Please key in Pin Count for Shift 3" min=0>
                  </td>
    
                  <td>
                        <input type="text" class="form-control" id="shift3Oa" name="shift3Oa" value="33" disabled>
                  </td>
    
                  <td>
                        <input type="number" class="form-control" id="shift4PinCount" name="shift4PinCount" placeholder="Pin Count" title="Please key in Pin Count for Shift 4" min=0>
                  </td>
    
                  <td>
                        <input type="text" class="form-control" id="shift4Oa" name="shift4Oa" value="44" disabled>
                  </td>
    
                  <td><input class="form-control" type="date" id="shiftDate" name="shiftDate" value="<?=date("Y-m-d")?>"></td>
    
                  <td>
                    <input type="submit" class="btn btn-primary" name="savePcData" id="savePcData" value="savePcData">
                  </td> 
    </form>
    </tr>
    <form method="post" action="">
    <tr>
           <td scope="row"></td>
           <input type ="text" name="sourece" value=3 />
                  <td>                         
                        <input type="number" class="form-control" id="shift1PinCount" name="shift1PinCount" placeholder="Pin Count" title="Please key in Pin Count for Shift 1" min=0>
                  </td>
    
                  <td>
                        <input type="text" class="form-control" id="shift1Oa" name="shift1Oa" value="111" disabled>
                  </td>
    
                  <td>
                        <input type="number" class="form-control" id="shift2PinCount" name="shift2PinCount" placeholder="Pin Count" title="Please key in Pin Count for Shift 2" min=0>
                  </td>
    
                  <td>
                        <input type="text" class="form-control" id="shift2Oa" name="shift2Oa" value="222" disabled>
                  </td>
    
                  <td>
                        <input type="number" class="form-control" id="shift3PinCount" name="shift3PinCount" placeholder="Pin Count" title="Please key in Pin Count for Shift 3" min=0>
                  </td>
    
                  <td>
                        <input type="text" class="form-control" id="shift3Oa" name="shift3Oa" value="333" disabled>
                  </td>
    
                  <td>
                        <input type="number" class="form-control" id="shift4PinCount" name="shift4PinCount" placeholder="Pin Count" title="Please key in Pin Count for Shift 4" min=0>
                  </td>
    
                  <td>
                        <input type="text" class="form-control" id="shift4Oa" name="shift4Oa" value="444" disabled>
                  </td>
    
                  <td><input class="form-control" type="date" id="shiftDate" name="shiftDate" value="<?=date("Y-m-d")?>"></td>
    
                  <td>
                    <input type="submit" class="btn btn-primary" name="savePcData" id="savePcData" value="savePcData">
                  </td> 
    </form>
    </tr>
    
    <?php
    
    if(isset($_POST['savePcData'])){
    
        echo "<pre>";
        print_r($_POST);
        die('mms');
    
    }
    
    
    ?> 
    

    Your Out put will be

    here sourece is your unique Id which helps you to update the data into your DB

    After submitting the form from any tr(row) you will redirect to same page with POST method and get data for that particular row on that page so you can easily update it as you want

    You can check this by using print_r($_POST); on same page

    If you have any questions please feel free to ask me...

    0 讨论(0)
提交回复
热议问题