obusitse
obusitse

Reputation:

multiple buttons that redirect to different location

I have four buttons in a form when i click each button it should direct me to its data. I have tried to write the ONCLICK direct to the page but nothing is happening. Do i need a script to activate that or what preferably Javascript

Upvotes: 0

Views: 4016

Answers (2)

Jabezz
Jabezz

Reputation: 1312

You need script to redirect from a button yes.

It can be inline, or in a form of a function.

Inline:

<input type="submit" onclick="javascript:window.location.href='somepage.html'">

As function:

<script>
    function Redirect(e, url) {
        window.event.returnValue = false; //prevent event in IE 
        e.preventDefault(); //prevent event in FF 
        window.location.href = url;
    }
</script>
<form>
    <input type="submit" onclick="Redirect(event, 'somepage.html');">
</form>

Upvotes: 0

RichieHindle
RichieHindle

Reputation: 281625

You can make each button change the action attribute of the form before it submits, like this:

<form id="myform" method="GET" action="data1.html">
<input type="submit" value="Go to Data 1"
       onclick="document.forms['myform'].action='data1.html'">
<input type="submit" value="Go to Data 2"
       onclick="document.forms['myform'].action='data2.html'">
</form>

Upvotes: 3

Related Questions