views:

1224

answers:

7

I am making a prototype and I want the search button to link to a sample search results page.

How do I make a button redirect to another page when it is clicked using jQuery.

+2  A: 

You can use:

  location.href = "newpage.html"

in the button's onclick event.

Vincent Ramdhanie
+2  A: 
$('#someButton').click(function() {
    window.location.href = '/some/new/page';
    return false;
});
Darin Dimitrov
+3  A: 

This should work ..

$('#buttonID').click(function(){ window.location = 'new url'});
Gaby
+3  A: 

is this what you mean?

$('button selector').click(function(){
   document.location.href='the_link_to_go_to.html';
})
Reigel
+1  A: 

You can use window.location

window.location="/newpage.php";

Or you can just make the form that the search button is in have a action of the page you want.

PetersenDidIt
+1  A: 

With simple Javascript:

<input type="button" onclick="window.location = 'path-here';">
Sarfraz
The OP want's it in jQuery..
Reigel
@Reigal: Or just JavaScript
meouw
+6  A: 

Without script:

<form action="where-you-want-to-go"><input type="submit"></form>

Better yet, since you are just going somewhere, present the user with the standard interface for "just going somewhere":

<a href="where-you-want-to-go">ta da</a>

Although, the context sounds like "Simulate a normal search where the user submits a form", in which case the first option is the way to go.

David Dorward
Who would have thought of a link? haha
meouw
+1 for the form. Since it will be a proper search form eventually you should do it like that now if possible.
DisgruntledGoat