I´m trying to compare values from an array with values in a combobox in jquery but with no success.
I have an array this way: (value 1,value 2,…) names separated with , (Example: john smith,peter pan,). On the other hand a combobox with values from a localstorage appended dynamically this way
$('select[name="selectListMenu1"]').append( new Option(nombre.fname + " " + nombre.lname) );
This gives me a final name like ‘John smith’ and I append it to the combo.
Now I want to compare each name in the array with each name in the combobox and get selected in the combobox the names that matches.
var summary3 = (elnombre.proycontac).split(","); // split the names to compare
var p1 = summary3.length // get the number of names to compare
$('[name="selectListMenu1"] ').each(function(){ //from here i get lost
for (a=0; a<=p1-2; a++) {
if ($(this).text())=== summary3[a] {
// select the name in combobox
}
}
});
You could try this:
I put an example here.