« Another HTML to PDF converter | Main | Parsing mail messages with PHP »
October 04, 2007
JS for iterating through all document elements
JS to select the options in all the select-one document elements where the text (as opposed to the value) == the value passed:
function select_option_by_text(my_text){ var els = document.getElementsByTagName('*'); //var regex = new RegExp(my_text + '.'); for(var i = 0; i < els.length; i++){ if(els[i].type == 'select-one'){ var opts = els[i].options; for(var o = 0; o < opts.length; o++){ var label = opts[o].text; if(label == my_text){ opts[o].selected = true; } } } } }
Tags: JavaScript
Posted by pj at October 4, 2007 09:51 AM