Adding options to a datalist.We will prepare a datalist without any option – value added to it.
We will use one array to store months of a year and then add them as option to the datalist. We will loop through all the elements of the array and prepare the format to store the options in a string variable by using all elements.
Then we will assign this string variable to the datalist by using innnerHTML property.
Each element of our array will be added as option values of the datalist.
The output is here . Full code is here
Number of options available in a Datalist
Output will be 12
Displaying particular option value.
Output will be June ( Note : options[0].value is January )
Adding options from MySQL table.Here we have seen how to add options to a datalist by using client side JavaScript. We can populate options of a datalist by taking data from database table by using PHP and Ajax.
This article is written by plus2net.com team.
![]() | ||||
![]() ![]()
| ||||