itazev Posted August 23, 2007 Share Posted August 23, 2007 Hey everyone! I tried to google it but I could not find how to get a text of a listbox/combobox element. Besides I tried getDataProperty("text") but does not worked. I appreciate your help! Quote Link to comment Share on other sites More sharing options...
emehrkay Posted August 23, 2007 Share Posted August 23, 2007 hmm, lets try to figure this out. if a select looks like this: <select id="test_select"><option>one</option><option>two</option></select> var sel = document.getElementById('test_select'); var sel_children = sel.childNodes; var opt = ''; for(var i = 0; i < sel_children.length; i++){ if(sel_children[i].hasChildNodes()){ opt += sel_children[i].firstChild.nodeValue +"\n"; } } alert(opt); that should work, havent tested it. adapted from http://developer.mozilla.org/en/docs/DOM:element.childNodes Quote Link to comment Share on other sites More sharing options...
emehrkay Posted August 23, 2007 Share Posted August 23, 2007 definitely had a massive brain fart <select id="test_select"><option>one</option><option>two</option></select> var opts = document.getElementById('test_select').getElementsByTagName('option'); var c = opts.length; for(x = 0; x < c; x++){ alert(opts[x].value); } Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.