Hello -
I am trying to populate a drop down HTML with data, specifically date values, via javascript.
Assume I have the select drop down list in HTML, with id "inceptionDates"
in the javascript, make reference to the HTML drop down list:
now the next assumption, a database call is made in the javascript to retrieve the data, stored in the variable inceptionDates below
The data in inceptionDates is simply
id, inceptiondate
id, inceptiondate
id, inceptiondate
etc...
Now I loop through the data, and attempt to translate the inceptiondate date value into the drop down list:
Trouble is, this results in the Id being populated in the drop down, rather than the inceptiondate, as intended.
Is there a way to get the date value populated into the ddl, rather then the id?
I am trying to populate a drop down HTML with data, specifically date values, via javascript.
Assume I have the select drop down list in HTML, with id "inceptionDates"
in the javascript, make reference to the HTML drop down list:
Code:
const inceptionDatesddl = document.getElementById("inceptionDates");
now the next assumption, a database call is made in the javascript to retrieve the data, stored in the variable inceptionDates below
The data in inceptionDates is simply
id, inceptiondate
id, inceptiondate
id, inceptiondate
etc...
Now I loop through the data, and attempt to translate the inceptiondate date value into the drop down list:
JavaScript:
for (let key in inceptionDates) {
let option = document.createElement("option");
option.setAttribute('value', data[key]);
let optionText = document.createTextNode(key);
option.appendChild(optionText);
inceptionDatesddl.appendChild(option);
}
Trouble is, this results in the Id being populated in the drop down, rather than the inceptiondate, as intended.
Is there a way to get the date value populated into the ddl, rather then the id?