April 4, 201412 yr Hello, I currently have an input field which I am using as a search field. I have incorporated JQuery Ajax so that when you start typing in the input field it uses what has been typed and creates an <ul> of all the names which contain the input letters (In the same order they have been typed). The <ul>, which appears, hovers over my other divs and only appears when there is text in the input field. So, for example, if you type something in the input field, and then delete them all, the <ul> would disappear. When selecting one of the names from the list, I use this to trigger another event which loads relevant fields in the page, with the corresponding data to the person who's name you have clicked. This then get's triggered: $(document).ready(function() { $(".search").change(function() { $('#search').val(''); }); }); This picks up on the event of clicking on a name from the drop-down list and it successfully clears the input field (After running my other queries). HOWEVER the floating <ul> does not disappear. You have to then click in the empty input field and press the backspace key for it to disappear. Hence why I am wanting to find out how to simulate a backspace press using javascript / jquery. Any help with this matter will be greatly appreciated as I have been stumped with this for far too long now. Many thanks, - MjA - Edited April 4, 201412 yr by SkullBob
April 4, 201412 yr Would adding focus to the field work? $(document).ready(function() { $(".search").change(function() { $('#search').val('').focus(); }); }); Edited April 4, 201412 yr by Mikec1uk
April 4, 201412 yr Author @ Mikec1uk - I added the '.focus()' and this has still not fixed the issue. - MjA - Edited April 4, 201412 yr by SkullBob
April 4, 201412 yr Author @D4Y0 - I will send you a message with the details for where the site is hosted, and the login details, so you can have a look. I don't want to share sensitive information with too many people. - MjA -
April 4, 201412 yr No problem, try this code $(document).ready(function() { $(".search").change(function() { $('#search').val('').trigger("keyup"); }); });
April 7, 201412 yr Author Thank you so much. It can be so annoying spending so long on something to find out that you only needed to include the following to fix it. .trigger("keyup"); I was stuck with this for hours. Many thanks. - MjA -
Create an account or sign in to comment