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. (Last updated on : Nov 16th 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How get index field value

Thread ID:

Created:

Updated:

Platform:

Replies:

118103 Jan 31,2015 07:45 PM UTC Feb 2,2015 12:14 PM UTC JavaScript 1
loading
Tags: ejAutoCompleteTextBox
Kovács István
Asked On January 31, 2015 07:45 PM UTC

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.

Harikrishnan P [Syncfusion]
Replied On 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



CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

;