Select jQuery autocomplete value by its id

Lakshmana Kumar

I have 2 text box with jquery autocomplete. My requirement is

If i select Text Box 1 label or value aa and its id is 1, then in Text Box 2 label or value which contain id as 1 that is (aa1) should be selected.

I don't want to copy value or match value in Text Box 1 to Text Box 2 or vice versa.

And also i want to know how to select autocomplete value by passing its id?

Example :

If i select bb (id=2) in Text Box 1 then bb1 (id=2) in text Box 2 should be selected.

If i select cab1 (id=5) in Text Box 2 then cab (id=5) in text Box 1 should be selected.

Fiddle Demo

My HTML and jQuery

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML5//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
    <link href="css/jquery-ui-start-custom-1.10.3.css" rel="stylesheet" type="text/css" />
    <script src="scripts/jquery-1.10.2.min.js" type="text/javascript"></script>
    <script src="scripts/jquery-ui-custom-1.10.3.min.js" type="text/javascript"></script>
    <script type="text/javascript">
        $(document).ready(function() {

            var arraytxt1 = [{ id: 1, label: "aa" }, { id: 2, label: "bb" }, { id: 3, label: "bbbb" }, { id: 4, label: "abab" }, { id: 5, label: "cab"}];

            $("#txt1").autocomplete({
                source: arraytxt1,
                minLength: 1,
                select: function(event, ui) {
                    //$("#txt2").val(ui.item.label);
                    // Corresponding Text Box 2 value to selected.
                }
            });

            var arraytxt2 = [{ id: 1, label: "aa1" }, { id: 2, label: "bb1" }, { id: 3, label: "bbbb1" }, { id: 4, label: "abab1" }, { id: 5, label: "cab1"}];

            $("#txt2").autocomplete({
                source: arraytxt2,
                minLength: 1,
                select: function(event, ui) {
                   // Corresponding Text Box 1 value to selected.
                }
            });

        });
    </script>
</head>
<body>
    <div>
        Text Box 1
        <input type="text" id="txt1" />
        Text Box 2
        <input type="text" id="txt2" />
    </div>
</body>
</html>
Sruti
 $("#txt1").autocomplete({
                source: arraytxt1,
                minLength: 1,
                select: function(event, ui) {
                     var matching_right_side_option;
                    $.each(arraytxt2, function(index){
                        if(this.id === ui.item.id) 
                        {
                            matching_right_side_option = this;
                        }    

                    }); 
                 $("#txt2").val(matching_right_side_option.label);
                }
            });

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

jquery autocomplete with id and value does not work

From Dev

Select element with percent sign (%) in its id with jQuery

From Dev

Select Attribute value and field value Using jquery autocomplete

From Dev

how to get the value of id if its id is an integer value in jquery

From Dev

How to manually set the value (and trigger the select event) to jQuery autocomplete

From Dev

Knockout autocomplete with jquery doesn't allow to select custom value

From Dev

jQuery autocomplete select not triggered

From Dev

jQuery autocomplete select event

From Dev

Select where id is not exist and it its value is 'a specific value'

From Dev

Autocomplete selected value - Jquery

From Dev

Autocomplete selected value - Jquery

From Dev

Nokogiri: How to select the value of an attribute that contains periods in its id?

From Dev

dynamically bind input value to select list by its JSON data 'id'

From Dev

How select elements using jquery based on its id suffix and prefix?

From Java

jQuery - setting the selected value of a select control via its text description

From Dev

Get value of HTML select option using its index with jQuery

From Dev

use jQuery to select option from menu based on its text not value

From Dev

Jquery, how to select an element by its first position value of an attribute

From Dev

Select a tag with custom data value and change its href with jquery

From Dev

Muliple JQuery UI autocomplete select

From Dev

jQuery autocomplete select function not firing

From Dev

Bind ID as Value with Text in Autocomplete

From Dev

Autocomplete Jquery get id and name

From Dev

Autocomplete Jquery get id and name

From Dev

JQuery UI Autocomplete set default VALUE using ID (value) instead of Label

From Dev

How to get value jquery autocomplete?

From Dev

How to get value jquery autocomplete?

From Dev

Javascript select an ID by its name

From Dev

Clear autocomplete field value after select address

Related Related

  1. 1

    jquery autocomplete with id and value does not work

  2. 2

    Select element with percent sign (%) in its id with jQuery

  3. 3

    Select Attribute value and field value Using jquery autocomplete

  4. 4

    how to get the value of id if its id is an integer value in jquery

  5. 5

    How to manually set the value (and trigger the select event) to jQuery autocomplete

  6. 6

    Knockout autocomplete with jquery doesn't allow to select custom value

  7. 7

    jQuery autocomplete select not triggered

  8. 8

    jQuery autocomplete select event

  9. 9

    Select where id is not exist and it its value is 'a specific value'

  10. 10

    Autocomplete selected value - Jquery

  11. 11

    Autocomplete selected value - Jquery

  12. 12

    Nokogiri: How to select the value of an attribute that contains periods in its id?

  13. 13

    dynamically bind input value to select list by its JSON data 'id'

  14. 14

    How select elements using jquery based on its id suffix and prefix?

  15. 15

    jQuery - setting the selected value of a select control via its text description

  16. 16

    Get value of HTML select option using its index with jQuery

  17. 17

    use jQuery to select option from menu based on its text not value

  18. 18

    Jquery, how to select an element by its first position value of an attribute

  19. 19

    Select a tag with custom data value and change its href with jquery

  20. 20

    Muliple JQuery UI autocomplete select

  21. 21

    jQuery autocomplete select function not firing

  22. 22

    Bind ID as Value with Text in Autocomplete

  23. 23

    Autocomplete Jquery get id and name

  24. 24

    Autocomplete Jquery get id and name

  25. 25

    JQuery UI Autocomplete set default VALUE using ID (value) instead of Label

  26. 26

    How to get value jquery autocomplete?

  27. 27

    How to get value jquery autocomplete?

  28. 28

    Javascript select an ID by its name

  29. 29

    Clear autocomplete field value after select address

HotTag

Archive