<...">

Get all select / option lists starting with something

On the HTML page, I have a list of selections.

<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 a select / option list that starts with "salut-". For a list of abstracts, I want to compare its name and its selected value.

I know this is possible in jQuery, but cannot use jquery, only javascript (JSNI with GWT for sure).

Do you have an idea?

Thank!

+3


source to share


3 answers


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);

      



+5


source


You can use getElementsByTagName function to get each name SELECT

, for example:

var e = document.getElementsByTagName("select");
for (var i = 0; i < e.length; i++){
  var name = e[i].getAttribute("name");
}

      



Then you can use the following code to get each OPTION

for SELECT

in order to perform any comparisons you need:

var options = e[i].getElementsByTagName("option")

      

+2


source


var ModalListInputs =document.getElementById("checks")
        var arrayInput = ModalListInputs.getElementsByTagName("input");
        //console.log(arrayInput);

        for(var x=0; x <= arrayInput.length-1; x++){
            if(arrayInput[x].getAttribute("type")=="checkbox" && arrayInput[x].checked ==true){
                console.log(arrayInput[x].value);
            }
        }

      

-1


source







All Articles