function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
SasszzSasszz 

<option Selected =true> not working

whenever i  load the page , the option is automatically selects the last
value of the picklist. <option Selected> is not working.
how can i make the particular option value to Selected? 
pls help me on this.

HTML
<select size="1" name="Country Name" onchange={changeHandler}>
              <template for:each={CountryList} for:item="country">
   <option  selected={selectedCountry} key={country.key} value={country.Id}> 
      {country.Name}</option>
              </template>
  </select>
---------------------------------------------------------------------------------------------------------
js
 @track selectedCountry=false;
 @api countryId='';
 connectedCallback() {
 getCountry({
        recordId: this.countryId,
    })
.then(result => {
      this.CountryList= result;
      if(this.countryId){
        Object.entries(this.CountryList).forEach(
          ([key]) => {
            if(this.countryId === this.CountryList[key].Id){
              this.selectedCountry = true;
}
}

 
David Zhu 🔥David Zhu 🔥
I would suggest using lightning-combobox component.

https://developer.salesforce.com/docs/component-library/bundle/lightning-combobox/example