I highly recommend you use the regular submit button form for this. In this case, you donβt even need to use JavaScript at all. For instance:
<form action="http://www.google.com/search">
<input id="textbox" name="q" type="text" value="" size="25" />
<input type="submit" value="Search" />
</form>
If you really want to use the provided markup, it is best to add an ID to the element a, for example. searchButtonand then do:
document.getElementById("searchButton").onclick = doSearch;
function doSearch() {
var v = document.getElementById("textbox").value;
window.location = "http://www.google.com/search?q=" + encodeURIComponent(v);
return false;
}
source
share