Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

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.

share|improve this question
I had asked for js because I didn't imagine that a simple HTML solution was available. Thanks it solved my purpose. – Ankur Feb 11 '10 at 8:57

9 Answers

up vote 27 down vote accepted

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.

share|improve this answer
4  
Who would have thought of a link? haha – meouw Feb 10 '10 at 16:36
+1 for the form. Since it will be a proper search form eventually you should do it like that now if possible. – DisgruntledGoat Feb 10 '10 at 16:41
+1 for non-JavaScript solution – Alexander Farber Sep 11 '11 at 7:56

is this what you mean?

$('button selector').click(function(){
   document.location.href='the_link_to_go_to.html';
})
share|improve this answer
$('#someButton').click(function() {
    window.location.href = '/some/new/page';
    return false;
});
share|improve this answer

With simple Javascript:

<input type="button" onclick="window.location = 'path-here';">
share|improve this answer
The OP want's it in jQuery.. – Reigel Feb 10 '10 at 16:26
2  
@Reigal: Or just JavaScript – meouw Feb 10 '10 at 16:35

This should work ..

$('#buttonID').click(function(){ window.location = 'new url'});
share|improve this answer

You can use:

  location.href = "newpage.html"

in the button's onclick event.

share|improve this answer

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.

share|improve this answer

And in Rails 3 with CoffeeScript using unobtrusive JavaScript (UJS):

Add to assets/javascripts/my_controller.js.coffee:

$ ->
  $('#field_name').click ->
    window.location.href = 'new_url'

which reads: when the document.ready event has fired, add an onclick event to a DOM object whose ID is field_name which executes the javascript window.location.href='new_url';

share|improve this answer

Wrap it in a link

<a href="http://www.google.com"><button type="button">button</button></a>
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.