in my plain HTML page, i had a textbox for user to input keyword and then redirect to asp page.
i use javascript to capture keywords when user click submit button.
but when user press enter, the HTML page will reload and return error page.
how can i capture enter key event ? so that it will redirect to asp page.
thanks
my javascript code as follows:
function searching() {
var keywordsStr = document.getElementById('keywords').value;
var cmd = "http://xxx/SearchEngine/Searching.aspx?keywords=" + encodeURI(keywordsStr) ;
window.open(cmd);
}
my html code as follow:
<form name="form1" method="post" action="" >
<input name="keywords" type="text" id="keywords" size="50" >
<input type="submit" name="btn_search" id="btn_search" value="Search" onClick="javascript:searching(); return false;">
<input type="reset" name="btn_reset" id="btn_reset" value="Reset">
</form>
your ‘action’ attribute is empty, which means the HTML page will post to itself (reloading basically). You need to put the URL of your ASP page in there to be able to post the data.
and you might want to change the method to
method="get"to mimic your javascript function.If you want the submit to create a new window, you can add a target attribute to the form: