I am having 1 Array in which my Source and Destination are like this:
markers.push({
"Location": "Chicago",
"IsLocation": "Yes"
});
markers.push({
"Location": "Los Angeles",
"IsLocation": "Yes"
});
Now when i will create points with my dynamic textbox then i would like to add those all points in between source and destination.
Scenario 1:1st dynamic textbox with input say for Eg:abc
markers[0]:Chicago
markers[1]:abc
marker[2]:Los Angeles.
Scenario 2:2nd dynamic textbox with input say for Eg:pqr
markers[0]:Chicago
markers[1]:abc
markers[2]:pqr
marker[3]:Los Angeles.
Scenario 3:3rd dynamic textbox with input say for Eg:lmn
markers[0]:Chicago
markers[1]:abc
markers[2]:pqr
markers[3]:lmn
marker[4]:Los Angeles.
My first position will be fixed.
Code:
// Code goes here
var cnt = 1;
var maxNumberOfTextboxAllowed = 5;
var autocomplete = [];
var markers = [];
markers.push({
"Location": "Chicago",
"IsLocation": "Yes"
});
markers.push({
"Location": "Los Angeles",
"IsLocation": "Yes"
});
function Generatetextbox() {
if (cnt <= maxNumberOfTextboxAllowed) {
var fieldWrapper = $("<div class='fieldwrapper' id='field" + cnt + "'/>");
var fName = $("<input type='text' class='fieldname' id='Txtopt" + cnt + "' name='TxtoptNm" + cnt + "' />");
fieldWrapper.append(fName);
fieldWrapper.append('<br />');
fieldWrapper.append('<br />');
$("#abc").append(fieldWrapper);
var newInput = [];
var newEl = document.getElementById('Txtopt' + cnt);
var txtboxId = 'Txtopt' + cnt;
newInput.push(newEl);
setupAutocomplete(autocomplete, newInput, 0, txtboxId);
cnt = cnt + 1;
} else
alert("Cant create more than 5 textbox")
}
function setupAutocomplete(autocomplete, inputs, i, txtboxId) {
autocomplete.push((txtboxId));
var idx = autocomplete.length - 1;
document.getElementById(autocomplete[idx]).addEventListener("change", function() {
alert(document.getElementById(autocomplete[idx]).value);
var autoTextbox = [{
"Location": document.getElementById(autocomplete[idx]).value,
"IsLocation": "Yes"
}]
var markerLastIndexData = [{
"Location": markers[markers.length - 1].Location,
"IsLocation": "Yes"
}]
markers[markers.length - 1] = autoTextbox;
markers[markers.length] = markerLastIndexData;
console.log(markers)
});
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="abc"></div>
<button onclick="Generatetextbox()" class="btn btn-primary" type="button">Add</button>
You can check in console.I am getting not proper result.
Console output coming undefine:
Expected Output are shown in my scenarios like:
marker[0]:{
Location="Chicago",
Isolcation="Yes"
}
marker[1]:{
Location="abc",
Isolcation="Yes"
}
etc......
