Skip to main content
deleted 1 character in body
Source Link
LP13
  • 34.8k
  • 63
  • 266
  • 473

I have several html input controls on a page and a search button. When user is outside the input controls, ( ie focus is not inside the input control) and if user clickspress enter, i want to trigger click event of search button. The search button is not a Submit button and it is not inside a form

<input type="text" id="input1" /> <input type="checkbox" id="input2" /> <input type="text" class="autocomplete" id="input3" /> <button type="button" id="btnSearch">Search</button> 

currently I am doing this

$(document).keypress(function (event) { if (event.keyCode === 13) { $("#btnSearch").click(); } }) 

However, the above code triggers click event every time user clicks enter.

Some of the input controls I have are custom autocomplete controls. Auto complete control shows multiple options as soon user starts typing something. Then user can select the option by using mouse or by pressing enter.

I don't want to trigger the click event of a search button when user press enter to select an option.

I have several html input controls on a page and a search button. When user is outside the input controls, ( ie focus is not inside the input control) and if user clicks enter, i want to trigger click event of search button. The search button is not a Submit button and it is not inside a form

<input type="text" id="input1" /> <input type="checkbox" id="input2" /> <input type="text" class="autocomplete" id="input3" /> <button type="button" id="btnSearch">Search</button> 

currently I am doing this

$(document).keypress(function (event) { if (event.keyCode === 13) { $("#btnSearch").click(); } }) 

However, the above code triggers click event every time user clicks enter.

Some of the input controls I have are custom autocomplete controls. Auto complete control shows multiple options as soon user starts typing something. Then user can select the option by using mouse or by pressing enter.

I don't want to trigger the click event of a search button when user press enter to select an option.

I have several html input controls on a page and a search button. When user is outside the input controls, ( ie focus is not inside the input control) and if user press enter, i want to trigger click event of search button. The search button is not a Submit button and it is not inside a form

<input type="text" id="input1" /> <input type="checkbox" id="input2" /> <input type="text" class="autocomplete" id="input3" /> <button type="button" id="btnSearch">Search</button> 

currently I am doing this

$(document).keypress(function (event) { if (event.keyCode === 13) { $("#btnSearch").click(); } }) 

However, the above code triggers click event every time user clicks enter.

Some of the input controls I have are custom autocomplete controls. Auto complete control shows multiple options as soon user starts typing something. Then user can select the option by using mouse or by pressing enter.

I don't want to trigger the click event of a search button when user press enter to select an option.

grammar, tags
Source Link
Travis J
  • 82.6k
  • 43
  • 213
  • 280

I have several html input controls on a page and a search button. When user is outside the input controls, ( ie focus is not inside the input control) and if user clicks enter, i want to trigger click event of search button. The search button is not a Submit button and it is not inside a form

<input type="text" id="input1" /> <input type="checkbox" id="input2" /> <input type="text" class="autocomplete" id="input3" /> <button type="button" id="btnSearch">Search</button> 

currently iI am doing this

 $(document).keypress(function (event) {   if (event.keyCode === 13) {   $("#btnSearch").click();   }  }) 

However, the above code triggers click event every time user clicks enter.

Some of the input controls iI have are custom autocomplete controls. Auto complete control shows multiple options as soon user startstarts typing something. Then user can select the option by using mouse or by pressing enter.

I don't want to trigger the click event of a search button when user press enter to select an option.

I have several html input controls on a page and a search button. When user is outside the input controls, ( ie focus is not inside the input control) and if user clicks enter, i want to trigger click event of search button. The search button is not a Submit button and it is not inside a form

<input type="text" id="input1" /> <input type="checkbox" id="input2" /> <input type="text" class="autocomplete" id="input3" /> <button type="button" id="btnSearch">Search</button> 

currently i am doing this

 $(document).keypress(function (event) {   if (event.keyCode === 13) {   $("#btnSearch").click();   }  }) 

However, above code triggers click event every time user clicks enter.

Some of the input controls i have are custom autocomplete controls. Auto complete control shows multiple options as soon user start typing something. Then user can select the option by using mouse or by pressing enter.

I don't want to trigger click event of a search button when user press enter to select an option.

I have several html input controls on a page and a search button. When user is outside the input controls, ( ie focus is not inside the input control) and if user clicks enter, i want to trigger click event of search button. The search button is not a Submit button and it is not inside a form

<input type="text" id="input1" /> <input type="checkbox" id="input2" /> <input type="text" class="autocomplete" id="input3" /> <button type="button" id="btnSearch">Search</button> 

currently I am doing this

$(document).keypress(function (event) { if (event.keyCode === 13) { $("#btnSearch").click(); } }) 

However, the above code triggers click event every time user clicks enter.

Some of the input controls I have are custom autocomplete controls. Auto complete control shows multiple options as soon user starts typing something. Then user can select the option by using mouse or by pressing enter.

I don't want to trigger the click event of a search button when user press enter to select an option.

Source Link
LP13
  • 34.8k
  • 63
  • 266
  • 473

How to trigger button click when press enter key outside of input controls

I have several html input controls on a page and a search button. When user is outside the input controls, ( ie focus is not inside the input control) and if user clicks enter, i want to trigger click event of search button. The search button is not a Submit button and it is not inside a form

<input type="text" id="input1" /> <input type="checkbox" id="input2" /> <input type="text" class="autocomplete" id="input3" /> <button type="button" id="btnSearch">Search</button> 

currently i am doing this

 $(document).keypress(function (event) { if (event.keyCode === 13) { $("#btnSearch").click(); } }) 

However, above code triggers click event every time user clicks enter.

Some of the input controls i have are custom autocomplete controls. Auto complete control shows multiple options as soon user start typing something. Then user can select the option by using mouse or by pressing enter.

I don't want to trigger click event of a search button when user press enter to select an option.