user244394
user244394

Reputation: 13448

Form not submitting when enter key is pressed

When I press the search button, I get the result fine. But when , i press enter I want to be able to search as well.

Problem is when I press enter it just reloads the place and goes to displaylist(). How can I make this work?

I have the following code html and JS below.

HTML

<div class="input-group">
             <span class="input-group-btn">
               <button id="basic-search" class="btn btn-default " type="button" > <span class="glyphicon glyphicon-search" aria-hidden="true"></span></button>
           </span>              
           <input type="text"  id="basicsearchVal" class="form-control" placeholder="Enter a Ticker Symbol,CERT, BHCor a fragment of a Bank Name,." autocomplete="on">

</div>

JS

$(document).ready(function () {

        var newURL;
        var SearchData;       
        var detailPageUrl ="summary.html";   
        var mydata;

        displaylist(detailPageUrl,mydata,newURL);

        $("#basicsearchVal").keydown(function(e) {
            if (this.value != '') {
               console.log( "this.value keydown " +this.value);
                $(".search-result").jqGrid('GridUnload');
                var searchInput = $("#basicsearchVal").val()
                $("#pageTitle").html("Search Result(s) for <span class='text-primary'>" +searchInput+ "</span>")
                $( "#watchlist-b").remove();
                $("#watchList-b1").remove();
                $("#watchList-b2").remove();
                SearchData =newURL +"/services-monitor/GetQuickSearch?searchString="+searchInput;
                console.log("SearchData " +SearchData);
                displaySearchResult(detailPageUrl,SearchData,mydata); 

                jQuery(".search-result").trigger("reloadGrid");

            } else {
                 console.log( "Please enter a Name to search" +this.value);
            }
        });





    });

Upvotes: 0

Views: 727

Answers (1)

h-rai
h-rai

Reputation: 3964

Change your button type to 'submit' in the button tag.

Upvotes: 3

Related Questions