dimanche 21 février 2016

remove checkbox and text value when combobox change

I have an issue with my code. I hope anybody here can help me to fix it. I have problem in remove value from text when combobox change.

Here is my js code:

<script>
$(document).ready(function(){
    $('.select').change(function(){
        var check =   $(this).closest('tr').find("input[type='checkbox']").attr('id');
        $('#'+check+'').prop("checked",false);
        var txt = $(this).closest('tr').find("input[type='text']").attr('id');
        $('#'+txt+'').val("");
    });
});
</script>

And here is my HTML code:

<html>
   <head>
      <meta http-equiv="Content-Type" content="text/html" />
   </head>
      <body>
         <table>
            <tr>
               <th>SELECT TYPE</th>
               <th>TAKE IT</th>
               <th>YOUR CHOOSEN</th>
            </tr>
            <tr>
               <td><select class="select" name="select1"><option>--CHOOSE--</option><option value="Cars">Cars</option><option value="Bike">Bike</option></select</td>
               <td><input type="checkbox" name="check1" /></td>
               <td><input type="text" name="input1" /></td>
            </tr>
            <tr>
               <td><select class="select" name="select2"><option>--CHOOSE--</option><option value="Cars">Cars</option><option value="Bike">Bike</option></select</td>
               <td><input type="checkbox" name="check2" /></td>
               <td><input type="text" name="input2" /></td>
            </tr>
            <tr>
               <td><select class="select" name="select3"><option>--CHOOSE--</option><option value="Cars">Cars</option><option value="Bike">Bike</option></select</td>
               <td><input type="checkbox" name="check3" /></td>
               <td><input type="text" name="input3" /></td>
            </tr>
         </table>
      </body>
</html>

Note: I loading data from database and showing the result into text and checkbox automatically checked according to customer choice. When the customer want to edit data so, they will change the combobox and the text and checkbox should be clear. I only can remove the checked checkbox but can't clear the text. Anybody please help. I really appreciate for any help.




Aucun commentaire:

Enregistrer un commentaire