I have two select boxes.
<select id="select-district">
<option value="COL">COLOMBO</option>
<option value="GAL">GALLE</option>
<option value="MAT">MATARA</option>
<option value="KEG">KEGALLE</option>
<option value="KAND">KANDY</option>
<option value="JAFF">JAFFNA</option>
</select>
<select id="hidden-district">
<option value="1">COLOMBO</option>
<option value="2">GALLE</option>
<option value="3">MATARA</option>
<option value="4">KEGALLE</option>
<option value="5">KANDY</option>
<option value="6">JAFFNA</option>
</select>
I also i have my jQuery code as follows:
$(document).ready(function() {
$('#select-district').change(function() {
var lngLatdist = $('#select-district option:selected').text();
$("#hidden-district option:contains("+ lngLatdist +")").attr('selected', 'selected');
});
});
And here is the JSFiddle
The problem is when i select GALLE
from #select-district
it Shows KEGALLE
on #hidden-distrct
. Is there a way to select exact same word from the select boxes? Please help.
You can use .filter
and also .prop
::
$("#hidden-district option").filter(function() {
return $(this).text() == lngLatdist;
}).prop("selected", true);
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다