views:

1164

answers:

1

Hello, I have:

<select id="country" onchange="updateHtml(this.value);"></select>

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?

Thanks.

+2  A: 
document.getElementById('country').value=countryCode
BYK
Strange, document.getElementById('country').value=countryCodealert(document.getElementById('country').value)alerts valid "countryCode", but in combobox the old (first) value is still selected, why?
Ok, found the problem, it doesnt work when <select> is inside invisible div.