I'm having trouble increasing the value of the checkbox automatically which is sitting inside a table. So, in short, In my HTML table, I have text boxes and a checkbox present as a row(default 5 rows are shows when the webpage is loaded). I have a button that calls below javascript to automatically clone a row, if anytime end-user wants to add more rows to this existing default 5 rows HTML table.
<script type="text/javascript">
function cloneRow() {
var table = document.getElementById("tableToModify"); // find table to append to
var row = document.getElementById("rowToClone");
var clone = row.cloneNode(true); // copy children too
clone.id = "newID"; // change id or other attributes/contents
table.appendChild(clone); // add new row to end of table
}
// This function deletes a row when clicked on the button
function deleteRow(r) {
var i = r.parentNode.parentNode.rowIndex;
document.getElementById("myTable").deleteRow(i);
}
Now in my HTML, the checkbox looks like this : PS: The value "3" indicates rows number, so here in this example this checkbox is located in 3rd rows.
<tr id="rowToClone">
<td id="Transportation_Type">
<select id="Transportation_Type" onChange="checkOption(this)" name="transportation_type">
{% for type in transportation_type %}
<option value="{{ type.type }}">{{ type.type }}</option>
{% endfor %}
</select>
</td>
<td><input type="text" id="License_Plate" name="License_Plate" placeholder="Optional" style="text-align:center;" disabled></td>
<td><input id="checkbox" type="checkbox" name="Electric" value="3"/></td>
<td id="Number of days per week" >
<select name="DaysPerWeek">
<option selected>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
<option>5</option>
</select>
</td>
<td><input type="number" name="DistanceInKm" style="text-align:center;" ></td>
<td><button class="button is-danger " onclick="deleteRow(this)">Delete Row</button></td>
</tr>
So now my question is when clicking the clone button, how a new row will get the next value in the checkbox?
Let's say the end-user clicks a one-time clone button, then the checkbox along with others will be clone but only the value of checkbox should be "6" automatically.