I have been working on this system for a while now, and I've run into a small problem.
What I want to do: Copy all the data entered in an input field with id 'totalentered' into all the input fields with id 'totalclasses'
What is happening instead: There are multiple fields with the id 'totalclasses', generated using a while loop in PHP. However, the data is only being copied to the first input field with id 'totalclasses', rest of them remaining unchanged.
I'm just not able to figure out what's wrong. Here's my HTML+PHP code
<input type="text" class="form-control" placeholder="Total Classes Taken" id="totalentered">
<!--PHP Code, deleted because it would make reading this post too tiresome-->
<tr>
<th scope="row"><?=$row['rollnumber']?></th>
<td><?=$row['name']?></td>
<td><?php echo $selectedmonth; ?></td>
<td><input data-parsley-type="digits" type="text" class="form-control" placeholder="Classes Attended" name="attended<?= $cnt; ?>" id="attended"></td>
<td><input data-parsley-type="digits" type="text" class="form-control" placeholder="Total Classes Taken" id="totalclasses" name="totalclasses<?= $cnt; ?>"></td>
<input type="hidden" name="student_id<?= $cnt; ?>" value="<?=$student_id?>">
<input type="hidden" name="testmarks<?= $cnt; ?>" value="0">
<input type="hidden" name="assignmentmarks<?= $cnt; ?>" value="0">
<input type="hidden" name="submitted" value="true">
Here's my JavaScript code which should be doing the job:
<script type="text/javascript">
$(document).ready(function() {
$('form').parsley();
});
$(function() { // <== Doc Ready
$("#totalentered").change(function() { // When the total number of classes are changed
$('#totalclasses').val(this.value); // copy it over to the individual student for convenience
});
});
</script>
Anyone who can help me out with what's wrong? Thanks in advance!