(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:
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?