Reputation: 6362
I have the following code:
<div class="search">
<input type="text" id="tbWasSearch" value="Search here..." class="project" onclick="this.value=''"/>
<input type="button" id="tbWasSeachButton" class="tbWasSeachButton" onclick="searchWas();" />
</div>
function searchWas() {
var txt = $("#tbWasSearch").val();
if (txt != "") {
var url = "http://eiff/server.pt?=" + txt;
window.open(url);
$("#tbWasSearch").val('');
}
}
I want that once i put text in tbWasSearch and press enter, the text entered with inoke searchWas(); Should be the same mechanism as when i put text and click the search button
How can this be done?
Upvotes: 0
Views: 462
Reputation: 1650
You use form something like this..
<script>
function searchWas() {
var txt = $("#tbWasSearch").val();
if (txt != "") {
var url = "http://eiff/server.pt?=" + txt;
window.open(url);
$("#tbWasSearch").val('');
}
}
</script>
<form action="javascript:searchWas();">
<div class="search">
<input type="text" id="tbWasSearch" value="Search here..." class="project" onclick="this.value=''"/>
<input type="button" id="tbWasSeachButton" class="tbWasSeachButton" />
</div>
</form>
Upvotes: 0
Reputation: 17288
Use keyuy event:
var reload = function(e) {
if (e.keyCode == '13')
searchWas();
};
$('#tbWasSearch').keyup(reload);
Upvotes: 0
Reputation: 5485
also , if you use form tag you can use :
$('form:first').submit();
Upvotes: 0
Reputation: 420
Using jQuery you can write something like this
$("#tbWasSearch").keyup(function(event){
if(event.keyCode == 13){
$("#tbWasSeachButton").click();
}
});
where 13 is the keyCode for the return key
Upvotes: 2