0

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?

1
  • 3
    Why don't you use form tags? Commented Sep 19, 2012 at 7:45

4 Answers 4

2

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

Sign up to request clarification or add additional context in comments.

Comments

0

Use keyuy event:

var reload = function(e) { if (e.keyCode == '13') searchWas(); }; $('#tbWasSearch').keyup(reload); 

Comments

0

also , if you use form tag you can use :

$('form:first').submit(); 

Comments

0
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> 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.