Click here to Skip to main content
15,885,914 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi,

I need to reset data from my page whenever user clicks on backspace.

My code is as below


JavaScript
$('#txtAfgModelGrpName').autocomplete({
                    source: function (request, response) {
                        $.ajax({
                            url: v_url,
                            data: "{ 'Name': '" + request.term + "' }",
                            dataType: "json",
                            type: "POST",
                            contentType: "application/json; charset=utf-8",
                            dataFilter: function (data) { return data; },
                            success: function (data) {
                                if (data == null || data.length == 0 || data.d == null) {
                                    data = "";
                                    data.d = "";
                                }
                                else {
                                    response($.map(data.d, function (item) {
                                        return {
                                            value: item.GrpName,
                                            id: item
                                        }
                                    }))
                                }
                            },
                            error: function (err) {

                                alert(err);
                            }
                        });
                    },
                    minLength: 3,
                    select: function (event, ui) {
                      
                        LoadData(ui.item.id.GrpSeq);
                        return true;
                    },
                    change: function (event, ui) {
                        debugger
                      

                    }

                })
      .focus(function () {
          if (this.value == "") {
              $(this).trigger('keydown.autocomplete');
          }
      });
Posted
Updated 25-Mar-15 23:06pm
v2
Comments
Afzaal Ahmad Zeeshan 26-Mar-15 5:07am    
What is the initial state of the web page, or where are you logging any changes to reset. Secondly, where are you handling the backspace?

Another thing that ticked in my mind was, is it some sort of button on the webpage (click) or the backspace button on keyboard (press)?
afzalkarani 26-Mar-15 5:17am    
Hi,

It can be backspace button on keyboard (press)?
Afzaal Ahmad Zeeshan 26-Mar-15 5:18am    
Didn't you get my question? I meant whether are you using the keyPress event or you are using some sort of backspace-like button inside the website?
afzalkarani 26-Mar-15 5:19am    
It can be backspace button.
Afzaal Ahmad Zeeshan 26-Mar-15 5:28am    
Then you can handle the keyPress event and check for code of the key. Then reset the data. I am unable to find what kind of data you're going to reset... But, you understand my point.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900