1

I have a jsp page. In that jsp have one form for the user activate functionality by selecting the users. and also i have one search field for search the user like

<div class="quick-search-input-container"> 
<label id="quick-search-input-label" for="quick-search-input">Quick Search</label><s:textfield  name="quick-search-input"  id="quick-search-input" maxlength="50" value=""></s:textfield>
        <input type="button" class="grey-button" name="quick-search-submit" id="quick-search-submit" value="Search" onclick="searchSubmit()" />
        </div>

by the on click i wrote an action for the search but i want to search when i click a enter button through the keyboard.

shall i have a form inside the form? Is it a best practice ? or any other solutions

jackyesind
  • 3,343
  • 14
  • 47
  • 74

2 Answers2

1

You can use AJAX for it. Just bind the onclick event of your search button to perform an ajax call to your servlet and then send the response back from your servlet and then display it at any place on your webapge.

Here is a nice tutorial that explains how to use Jquery Ajax in your jsp and send response from servlet : Login through database with the help of jQuery 'ajax' & JSP

Abubakkar
  • 15,488
  • 8
  • 55
  • 83
1

How about this solution?

function isEnterPressed(ev) {
if(ev.keyCode==13) {searchSubmit();return false;}
}
<s:textfield  name="quick-search-input"  id="quick-search-input" maxlength="50" value="" onkeypress="isEnterPressed(event)"></s:textfield>
vusan
  • 5,221
  • 4
  • 46
  • 81