You need to cancel the form submit. Try changing the code to as follows:
<script>
$(document).ready(function(){
$("#searchbutton").click(function(){
var q;
q=$("#bar").val();
window.location = "https://www.google.com/search?q="+q;
});
$('#form').submit(function(){
var q;
q=$("#bar").val();
window.location = "https://www.google.com/search?q="+q;
event.preventDefault();
});
});
</script>
UPDATE
When you hit the enter key, the form will initiate the submit event. By default, the page will submit to itself if you don't specify a destination (in the action attribute). Since you are not cancelling the submit event, even though you were trying to redirect the user to a different page, the page submit will take presidence and completes the submit; therefore, the page never redirects to google.com.
Also, as @Quentin mentioned in his comment, it best practice to change:
$("#searchbutton").click(function(){
to
$("#searchbutton").click(function(event){
since the event object is handled differently across different browsers.