Last active
December 12, 2018 09:42
-
-
Save poudelmadhav/38283889354c1f5056984c321427d02d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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