Zelid
Zelid

Reputation: 7195

Prototype make option in select be selected by provided value

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?

Upvotes: 2

Views: 12403

Answers (2)

sstringer
sstringer

Reputation: 516

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.

Upvotes: 7

BYK
BYK

Reputation: 1374

document.getElementById('country').value=countryCode

Upvotes: 4

Related Questions