javascriptdomjsni

Get all select/option lists start by something


In an HTML page i have severals list.

<select name="salut-1358937506000-OK">
<option selected="" value="OK">OK</option>
<option value="OK">NOK</option>
</select>

<select name="salut-1358937582000-OK">
<option selected="" value="OK">OK</option>
<option value="OK">NOK</option>
</select>
...

In javascript, I want to get all select/option list which started by "salut-". For theses list, i want to compare his name and his selected value.

I know it is possible in jQuery but can't use jquery, only javascript (JSNI with GWT exactly).

Have you an idea?

Thanks!


Solution

  • var selects = document.getElementsByTagName('select');
    var sel;
    var relevantSelects = [];
    for(var z=0; z<selects.length; z++){
         sel = selects[z];
         if(sel.name.indexOf('salut-') === 0){
             relevantSelects.push(sel);
         }
    }
    console.log(relevantSelects);