• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
checkbox based input item

#11
(08-25-2018, 12:18 AM)Wouter60 Wrote: Give the inputs for the number of sets a name also: name="sets[]".
Remove the onChange part that you already have.

Then, in the jQuery part that starts with $(document).ready .. insert this:
Code:
    $("input[name='sets[]']").change(function(){
        row = $(this).parents('tr');
        n = $(this).val();
        f = row.find("input[name='india[]']").val();
        total = n * f;
        alert(total);
    });

Now, if you change any of the inputs with the name "sets[]", it will trigger a calculation.
Not working
************
echo '<td id="textone_'.$row['id'].'">'.$row['fee']. '</td>'; 
  echo '<td id="texttwo_'.$row['id'].'"> 
  <input type="number" min="0" max="999" name="india"  
   class="txtbox" disabled="disabled" ></td>';
   echo '<td> <input type="text" value="0"
   id="result_'.$row['id'].'" name="result"></td>';


<script src="//ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script> 
 <script type="text/javascript">
$(document).ready(function(){
$("input[name='sets[]']").change(function(){
        row = $(this).parents('tr');
        n = $(this).val();
        f = row.find("input[name='india[]']").val();
        total = n * f;
        alert(total);
    });

</script>
Reply

#12
The jQuery script is looking for an input named "sets[]". If that doesn't exist on the page, nothing will happen.
The inputs should have a name with brackets, like india[], not india, and sets[] rather than sets.
Thats because you build the inputs in a loop, and every input should get a unique name. If you use "india" as the name, only the first element with that name will be posted when you submit the form. If the name is "india[]", the result will be an array of values when the form is submitted.
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.