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! Link to comment https://forums.phpfreaks.com/topic/66348-get-text-form-listbox/ 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 Link to comment https://forums.phpfreaks.com/topic/66348-get-text-form-listbox/#findComment-332075 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); } Link to comment https://forums.phpfreaks.com/topic/66348-get-text-form-listbox/#findComment-332086 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.