Skip to content

Instantly share code, notes, and snippets.

@poudelmadhav
Last active December 12, 2018 09:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save poudelmadhav/38283889354c1f5056984c321427d02d to your computer and use it in GitHub Desktop.
Save poudelmadhav/38283889354c1f5056984c321427d02d to your computer and use it in GitHub Desktop.
<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">
<thead>
<tr>
<th>Day</th>
<th>Itineraries</th>
</tr>
</thead>
<tbody id="myTable">
<!-- Here td and tr will be appended -->
</tbody>
</table>
<script>
function addItineraryDays() {
let value = document.getElementById('days').value;
let table = document.getElementById("myTable");
$(table).empty();
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[]">' +
'</label>';
cell2.innerHTML = '<label>' +
'<input type="text" name="itinerary_details[]">' +
'</label>';
}
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment