views:

212

answers:

6

I have a regular form with a url as action to which the form submits when the submit button is clicked (or enter is pushed).
Now I need a second button that goes to another page. I know I should be using a link for this, but as to client's requirements, it should look like a button.
Because the CSS sheets are not made in-house (and communication is made impossible for me) I need a button in the form and thus cannot use a second form for the button.

I thought that either of the following tags could do the job:

<input type="button">

or

<button>

Can I set either of those to navigate to a link without using javascript?

A: 
<input type="button" onclick="document.location='my_other_link'" value="Click here"/>
aivarsak
This sollution uses javascript
borisCallens
Sorry, I missed "without using javascript" part
aivarsak
+1  A: 

no you must use javascript

<input type="button" value="go" onclick="javascript:location.href='http://www.stackoverflow.com';" />

Jeroen Dierckx
A: 

It can't be done in pure HTML.

Edit: Excepting, of course, Peter's Method

James Burgess
A: 

change the form's action dynamically:

here is javascript code:

function submitAnotherURL(){
 var yourForm = document.your_form_name;
 yourForm.action='your_other_link';
 yourForm.submit();
}

the button in html:

<input type="button" onclick="submitAnotherURL()" value="Click here"/>
jscoot
The OP wanted a non-JS solution.
James Burgess
+3  A: 

The only way to do this without using JavaScript is to have the second button inside a second form, whose action is the desired destination. You may be able to use CSS to position this second button 'inside' the first form.

Peter Hilton
Yes, this was what I was fearing. so to answer the OP: "No" :)Thanks for your reply
borisCallens
+2  A: 

You can do this with either:

  • A second form

  • Javascript

  • CSS to mock the appearance of a button on an anchor link

It seems you've ruled all three out in the question, but perhaps you've left a small window for inline styling (you say you have no control over the "CSS sheets" but that leaves room for a style attribute), but this solution will of course not pass any of the form info to the other page.

annakata
The first and third options sound like the best bet, he doesn't want to use Javascript though, so the second one is out. I'd pick the third option, but that's just a matter of preference. Just cause it has to look like a button doesn't mean it has to be a button.
dhulk
The first option is out if he happens to be in asp.net, personally I'd choose door number 3 too
annakata