If you want a single JavaScript object such as the following:
{ uniqueIDofSelect: "uniqueID", optionValue: "2" }
(where option 2, "Absent", is the current selection)
then the following code should produce it:
var jsObj = null;
var status = document.getElementsByName("status")[0];
for (i = 0, i < status.options.length, ++i) {
if (options[i].selected ) {
jsObj = { uniqueIDofSelect: status.id, optionValue: options[i].value };
break;
}
}
If you want an array of all such objects (not just the selected one), use michael's code but swap out status.options[i].text
for status.id
.
If you want a string that contains a JSON representation of the selected object, use this instead:
var jsonStr = "";
var status = document.getElementsByName("status")[0];
for (i = 0, i < status.options.length, ++i) {
if (options[i].selected ) {
jsonStr = '{ '
+ '"uniqueIDofSelect" : '
+ '"' + status.id + '"'
+ ", "
+ '"optionValue" : '
+ '"'+ options[i].value + '"'
+ ' }';
break;
}
}