tags:

views:

65

answers:

3

how to make a input type=button act like a hyperlink and redirect using a get request?

+2  A: 

Use input type="submit" instead and alter or omit the method attribute of the parent form element so that it defaults to GET.

<form action="http://stackoverflow.com"&gt;
    <input type="submit" value="press here">
</form>

If you really insist in using input type="button", then your only resort is JavaScript.

BalusC
A: 

Try links styled by Jquery UI: http://www.filamentgroup.com/lab/styling_buttons_and_toolbars_with_the_jquery_ui_css_framework

bpeterson76
Adding a form without doing anything useful with it, depending on JavaScript, adding a frame to the mix for no apparent reason, and not writing the JS in an unobtrusive fashion. Eugh.
David Dorward
A: 

There are several different ways to do that -- first, simply put it inside a form that points to where you want it to go:

<form action="/my/link/location" method="get">
    <input type="submit" value="Go to my link location" 
         name="Submit" id="frm1_submit" />
</form>

This has the advantage of working even without javascript turned on.

Second, use a stand-alone button with javascript:

<input type="submit" value="Go to my link location" 
    onclick="javascript:window.location='/my/link/location';" />

This however, will fail in browsers without javascript.

The third option is to style an actual link like a button:

<style type="text/css">
.my_content_container a {
    border-bottom: 1px solid #777777;
    border-left: 1px solid #000000;
    border-right: 1px solid #333333;
    border-top: 1px solid #000000;
    color: #000000;
    display: block;
    height: 2.5em;
    padding: 0 1em;
    width: 5em;
    text-decoration: none;
}
// :hover and :active styles left as an exercise for the reader.
</style>

<div class="my_content_container>
    <a href="/my/link/location/">Go to my link location</a>
</div>

This has the advantage of working everywhere and meaning what you most likely want it to mean.

Sean Vieira