Welcome Guest, Not a member yet? Register   Sign In
checkbox based input item
#9

(08-24-2018, 07:41 AM)Wouter60 Wrote: To toggle the disabled property of the text inputs, first give all text and number inputs a class name and the disabled property: class="txtbox" disabled="disabled".
Then give the checkboxes the class name "cbx".

Load jQuery. Insert the following script:

Code:
<script>

$(document).ready(function(){
    $('.cbx').click(function(){
        v = $(this).is(':checked');
        row = $(this).parents('tr');
        if (v==true) {
            row.find('.txtbox').removeAttr('disabled');    
        }
        else {
            row.find('.txtbox').attr('disabled','disabled');
        }
        
    });

});

</script>

Now, if you click on one of the checkboxes, the text and number inputs on the same row are enabled or disabled.


Important:

Code:
$('.cbx')

is jQuery code for document.getElementsByClassName('cbx')
As you can see, jQuery makes your code far more simple!

Working perfectly.
Thanks a lot. You are the real programmer.
one more queries.
I want to multiply first and second field result should be in third field. It has 7 rows.

echo '<td id="textone_'.$row['id'].'">'.$row['fee']. '</td>'; 
  echo '<td  id="texttwo_'.$row['id'].'"> <input type="number" min="0" max="999" 
  name="india"  
  onChange="sum('.$row['id'].'); " class="txtbox" disabled="disabled" ></td>';
echo '<td> <input type="text" value="0"

   id="result_'.$row['id'].'" name="result"></td>';
Ajax 
****

<script src="//ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script> 

<!--<script src="<?php echo base_url(); ?>assets/jQuery-2.1.4.min.js"></script> -->

<script type="text/javascript">
 function sum(rowid) {
       var txtFirstNumberValue =  document.getElementById('textone_'+rowid).innerHTML;
       alert(txtFirstNumberValue );
       var txtSecondNumberValue = document.getElementById('texttwo_'+rowid).value;
       alert(txtSecondNumberValue ); 
       
       var result = parseInt(txtFirstNumberValue) * parseInt(txtSecondNumberValue);
       alert(result);
       if (!isNaN(result)) {
           document.getElementById('result_'+rowid).value = result;
       }
   }
  </script>

alert(txtSecondNumberValue ) shows undefined error.
how to solve this?
Reply


Messages In This Thread
checkbox based input item - by kvanaraj - 08-20-2018, 11:35 PM
RE: checkbox based input item - by Pertti - 08-21-2018, 12:28 AM
RE: checkbox based input item - by kvanaraj - 08-21-2018, 01:40 AM
RE: checkbox based input item - by Pertti - 08-21-2018, 02:02 AM
RE: checkbox based input item - by kvanaraj - 08-21-2018, 02:34 AM
RE: checkbox based input item - by kvanaraj - 08-24-2018, 12:54 AM
RE: checkbox based input item - by InsiteFX - 08-24-2018, 03:13 AM
RE: checkbox based input item - by Wouter60 - 08-24-2018, 07:41 AM
RE: checkbox based input item - by kvanaraj - 08-24-2018, 11:00 PM
RE: checkbox based input item - by Wouter60 - 08-25-2018, 12:18 AM
RE: checkbox based input item - by kvanaraj - 08-25-2018, 12:44 AM
RE: checkbox based input item - by Wouter60 - 08-25-2018, 02:54 PM



Theme © iAndrew 2016 - Forum software by © MyBB