I'm not exactly sure what you mean. Do you mean you want something like this?
{ select : [ {option: {value:1, text:"First"}},
{option: {value:2, text:"Second"}},
{option: {value:3, text:"Third"}},
{option: {value:4, text:"Fourth"}}
]
}
You can parse and stringify any object in Javascript with this. First you need to build up your object. You can do something like this:
var selectJson = {};
selectJson.select = new Array();
var select = document.getElementById("mySelectId");
for(var i = 0; i < select.options.length; i++) {
var option = select.options[i];
var optionJson = {};
optionJson.option = {value: option.value, text: option.text};
selectJson.select.push(optionJson);
}
Then use the stringifier to convert it into a JSON string.
Vivin Paliath
2010-03-16 16:28:51