We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

How get index field value

Hi Syncfusion,

I am a beginer that's why I have a question. I use javascript controls but I don't know how I can get autocompletetextbox field "index" value when submit button click.

I fill this control with php code

 var garbages = [<?php $garbagesType = new garbagesType();
                        $garbagesType->getGarbagesType();
                        for($i = 0; $i < $garbagesType->data()->count(); $i++) {
                            echo '{index:"'.$garbagesType->data()->results()[$i]->idGarbagesType.'" , garbageName:"'.$garbagesType->data()->results()[$i]->name.'"}, ';  
                        }?>];
       
        $("#garbageType").ejAutocomplete({
            showPopupButton: true,
            width: "100%",
            height: "34px",
            dataSource: garbages,
            fields: { key: "index", text: "garbageName" },
            showRoundedCorner: true
        });

I hope You can help me.

1 Reply

HP Harikrishnan P Syncfusion Team February 2, 2015 12:14 PM UTC

Hi Kovacs,

Thanks for using Syncfusion products.

Query: I use javascript controls but I don't know how I can get autocompletetextbox field "index" value when submit button click

We would like to inform you that, there is no inbuilt method to get the “index (i.e., key/id)” of Autocomplete value. In autocomplete we can type any values, so there may not be an “id” associated with each values. But, if the Autocomplete value has “id” associated with it means, we can get it in the “focusout” event of the Autocomplete. To achieve your requirement, in the “focusout” event, we need to compare the value in the Autocomplete textbox with each values in the data source. If both the values matches means, then we can get the “id” associated with it. Please refer the below code,

[Script]

        function onFocusOut(args) {

            // Value in the Autocomplete textbox is obtained from args

            var AutocompleteValue = args.value;

            //for loop that iterates for each object in the datasource "states"

            for (var data = 0; data < states.length; data++) {

                //check whether the value in the autocomplete textbox matches with any of the value in autocomplete datasource

                if (states[data].countryName === AutocompleteValue){

                    //Get the "index" of the matched value and store it in a variable

                    uniqueKey = states[data].index;

                    break;

                   }

            }

        }

For your convenience, we have attached a simple sample in the following location to showcase you requirement.

Sample Location: Get autocomplete key

Please check with the provided sample. If you need further assistance, please get back to us we will assist you gladly.

Regards,

HariKrishnan



Loader.
Live Chat Icon For mobile
Up arrow icon