I am trying to redirect to google search on simple form submit but it won’t work. Here is my code stripped:
<script type="text/javascript">
function search(){
alert("in function!");
var a = document.getElementById("searchbox").value;
a = "http://www.google.com/#q=" + a;
a = a.replace(" ","+");
alert(a);
document.location = a;
}
</script>
<form method="post" action="#" onSubmit="search()">
<input type="text" id="searchbox" />
</form>
I get no alerts at all.
Two things, first it works fine for me, http://jsfiddle.net/LzwAt/1/
Make sure you have the javascript in the head tag of the file, and don’t forget the submit button ;).
Also, if you just want to submit to google you could always just do:
EDIT:
try this: