<!DOCTYPE html>
<html>
<body>
<select id='selectid' onchange="selectchange()">
</select>
<script>
for (let i=0;i<10;i++)
{
var select = document.getElementById("selectid");
var option = document.createElement("option");
option.text = "text="+i;
option.value = i;
select.add(option);
}
function selectchange()
{
alert(document.getElementById("selectid").value);
}
</script>
</body>
</html>
Description
- Here i have been using javascript to add options for my select tag
I Needed
- I need to store more than one data using my existing javascript code like for value=1 option need to add another value for the option tag like value2=a, and for value=2 as value2=b
Example syntax
var select = document.getElementById("selectid");
var option = document.createElement("option");
option.text = "text="+i;
option.value = i;
option.value2 = a;
select.add(option);
I need to add two values for my option using the above syntax.
document.getElementById("selectid")?