Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
<input type="number" id="days"> <!-- the td and tr are added equal to this value -->
<input type="text" onfocus="addItineraryDays()"> <!-- function calling onfocus this input -->
<table class="table table-striped table-bordered">
<tbody id="myTable">
<!-- Here td and tr will be appended -->
function addItineraryDays() {
let value = document.getElementById('days').value;
let table = document.getElementById("myTable");
for (let i = 0; i < value; i++) {
let row = table.insertRow(0);
let cell1 = row.insertCell(0);
let cell2 = row.insertCell(1);
cell1.innerHTML = '<label>' +
'<input type="number" name="itinerary_days[]">' +
cell2.innerHTML = '<label>' +
'<input type="text" name="itinerary_details[]">' +
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment