panych
4/29/2015 - 4:51 PM

Get options of select element as JSON

Get options of select element as JSON

var selectOptionsAsJSON = function(selectEl) {
	var result = [], options = selectEl.options;
	
	for (var i=0; i < options.length; i++) {
		result.push({"text":options[i].text, "value":options[i].value});
	}

	window.prompt('Done. Copy text:', JSON.stringify(result));
	return result;
}