Prototype make option in select be selected by provided value
12,332
Solution 1
document.getElementById('country').value=countryCode
Solution 2
To answer your question, "ho do you do it with Prototype" more directly, change:
document.getElementById('country').value=countryCode
to...
$('country').value = countryCode;
They both do the same thing, though.
Author by
Zelid
Updated on July 24, 2022Comments
-
Zelid almost 2 years
populated by options (country list) using Protype:
for (var i = 0; i < j.length; ++i) { var opt = new Element('option', {value:j[i].country}) opt.innerHTML = j[i].country_name; country.appendChild(opt); }
now i need to make option to be selected by value, somethhing like
function selectByValue(countryCode) { // make option selected where option value == countryCode }
how to do it with Prototype?
-
Zelid almost 15 yearsStrange, document.getElementById('country').value=countryCode alert(document.getElementById('country').value) alerts valid "countryCode", but in combobox the old (first) value is still selected, why?
-
Zelid almost 15 yearsOk, found the problem, it doesnt work when <select> is inside invisible div.