Select box text equal to rather than Select Box text contains - jQuery

Chamara Keragala

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.

tymeJV

You can use .filter and also .prop ::

$("#hidden-district option").filter(function() {
    return $(this).text() == lngLatdist;
}).prop("selected", true);

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

분류에서Dev

how to select from database and populate in a text box on Vb. net

분류에서Dev

I want my disabled text will be the placeholder for my select box

분류에서Dev

Chrome select box option text is distorted when open

분류에서Dev

jquery ".append" issue in a select box

분류에서Dev

jquery append new select box on click

분류에서Dev

jquery multiple check box enable text field

분류에서Dev

How to make assigning text in a combo box via code automatically select the index?

분류에서Dev

select box validation

분류에서Dev

Animated text within box

분류에서Dev

How to get more than one value of text box using in condition

분류에서Dev

jQuery select elements that contains text from list of strings (possible without loop?)

분류에서Dev

Jquery callback when any select box option is chosen (not changed)

분류에서Dev

jQuery: show selected text in the alert box upon Ctrl+a

분류에서Dev

Not able to Select in Select Box over Menu

분류에서Dev

How to validate a second text box if there is a value in first text box?

분류에서Dev

how to concatenate two or more text box values in one text box

분류에서Dev

WPF Suggestion text box with MVVM

분류에서Dev

regex for text box to validate input

분류에서Dev

Android white text in search box

분류에서Dev

Vertical align text to a box next to it

분류에서Dev

Align text vertically in box in Dia?

분류에서Dev

jQuery .val() for select element returns text

분류에서Dev

How to set ordering for default selected value in jQuery select2 remote select box?

분류에서Dev

Jquery box animation for shrinking and expanding more than one box at a time

분류에서Dev

Text box data getting cleared, when I click on check box

분류에서Dev

Php MySQL changing limit by select box selection

분류에서Dev

Select Box onchange Update Multiple Items

분류에서Dev

Removing duplicated options from select box in PHP

분류에서Dev

HTML SELECT JS onchange() disable comment box

Related 관련 기사

  1. 1

    how to select from database and populate in a text box on Vb. net

  2. 2

    I want my disabled text will be the placeholder for my select box

  3. 3

    Chrome select box option text is distorted when open

  4. 4

    jquery ".append" issue in a select box

  5. 5

    jquery append new select box on click

  6. 6

    jquery multiple check box enable text field

  7. 7

    How to make assigning text in a combo box via code automatically select the index?

  8. 8

    select box validation

  9. 9

    Animated text within box

  10. 10

    How to get more than one value of text box using in condition

  11. 11

    jQuery select elements that contains text from list of strings (possible without loop?)

  12. 12

    Jquery callback when any select box option is chosen (not changed)

  13. 13

    jQuery: show selected text in the alert box upon Ctrl+a

  14. 14

    Not able to Select in Select Box over Menu

  15. 15

    How to validate a second text box if there is a value in first text box?

  16. 16

    how to concatenate two or more text box values in one text box

  17. 17

    WPF Suggestion text box with MVVM

  18. 18

    regex for text box to validate input

  19. 19

    Android white text in search box

  20. 20

    Vertical align text to a box next to it

  21. 21

    Align text vertically in box in Dia?

  22. 22

    jQuery .val() for select element returns text

  23. 23

    How to set ordering for default selected value in jQuery select2 remote select box?

  24. 24

    Jquery box animation for shrinking and expanding more than one box at a time

  25. 25

    Text box data getting cleared, when I click on check box

  26. 26

    Php MySQL changing limit by select box selection

  27. 27

    Select Box onchange Update Multiple Items

  28. 28

    Removing duplicated options from select box in PHP

  29. 29

    HTML SELECT JS onchange() disable comment box

뜨겁다태그

보관