in my code i'm using onclick method for a button. when i click this button dynamically it shows multiple textboxes with remove button. all this process are successfully running. but all the textboxes are displaying continuously. i want to display one textbox per line. Where i have to add br tag or /n ?
This is my code:
var button = document.getElementById('waypoint-input');
button.addEventListener("click", function() {
var parentNode = document.getElementById('waypoints-list');
var input = document.createElement('input');
input.type = 'text';
input.placeholder = 'Enter a waypoint location';
input.id = 'waypoint' + me.waypointIndex;
input.inputId = me.waypointIndex;
input.name = 'waypointlist';
input.addEventListener('input',
function() {
if (input.value == "") {
var waypoint = me.waypts.filter(function(obj) {
return obj.key === input.inputId;
})[0];
if (waypoint != null &&
typeof waypoint !== "undefined") {
var waypointIndexToRemove = me.waypts.map(
function(el) {
return el.key;
}).indexOf(input.inputId);
me.waypts.splice(waypointIndexToRemove, 1);
}
}
});
var removeInput = document.createElement('button');
removeInput.innerHTML = 'Remove';
removeInput.onclick = function() {
parentNode.removeChild(input);
parentNode.removeChild(removeInput);
var childInputs = parentNode.getElementsByTagName('input');
if (childInputs.length > 0) {
for (var i = 0; i < childInputs.length; i++) {
childInputs[i].inputId = i;
}
}
if (input.value != "" && input.value != null) {
var waypointIndexToRemove = me.waypts.map(function(el) {
return el.key;
}).indexOf(input.inputId);
me.waypts.splice(waypointIndexToRemove, 1);
for (var i = input.inputId; i < me.waypts.length; i++) {
me.waypts[i].key = me.waypts[i].key - 1;
}
me.route();
}
me.waypointIndex--;
}
parentNode.appendChild(input);
parentNode.appendChild(removeInput);
var waypointAutocomplete = new google.maps.places.Autocomplete(
input, {
/*placeIdOnly : true */
});
me.setupPlaceChangedListener(waypointAutocomplete, 'WYPT',
input.inputId);
me.waypointIndex++;
}, false);