Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make a submit button display as a link?

This is not working in IE:

.text-button { background: transparent; 
               text-decoration: none; 
               cursor: pointer; }



<input type="submit" class="text-button" value="vote+"/>

It displays a square button.

like image 968
Will Curran Avatar asked Jan 07 '11 18:01

Will Curran


People also ask

How do you make a link a submit button?

You can use href=”#top” or href=”#” to link to the top of the current page. To use the anchor tag as submit button, we need the help of JavaScript. To submit the form, we use JavaScript . submit() function.

How do you hyperlink a button in HTML?

The plain HTML way is to put it in a <form> wherein you specify the desired target URL in the action attribute. If necessary, set CSS display: inline; on the form to keep it in the flow with the surrounding text. Instead of <input type="submit"> in above example, you can also use <button type="submit"> .

Can a link have type submit?

Definitely, there is no solution with pure HTML to submit a form with a link ( a ) tag. The standard HTML accepts only buttons or images.

How do I link a submit button outside?

You can tie a submit button to a form that the button doesn't live inside of. The trick is to give the form an id and then reference that id with the button's form property. With this setup, clicking the Submit button will cause the form to be submitted.


6 Answers

Copied from this link you can make your button look like a link -

.submitLink {
  background-color: transparent;
  text-decoration: underline;
  border: none;
  color: blue;
  cursor: pointer;
}
submitLink:focus {
  outline: none;
}
<input type="submit" class="submitLink" value="Submit">
like image 89
Vishal Avatar answered Oct 02 '22 13:10

Vishal


<form name='test'>
    <a href="javascript:document.forms['test'].submit()">As a link</a>
</form>
like image 29
labue Avatar answered Oct 02 '22 13:10

labue


I needed to prepare a post redirect page and since those rely on submitting forms, I needed to place something on them to make them work even if javascript failed for some reason. If javascript fails then an anchor for submitting the form won't work either. I had to actually format the button to look like a link (so the redirect page looks like one). I based my solution on what Vishal wrote, but I made some small alterations to make it look better inline. Here is the result.

button
{
    padding:0;
    background-color:transparent;
    text-decoration:underline;
    border:none;
    border:0;
    color:blue;
    cursor:pointer;
    font-family:inherit;
    font-size:inherit;
}

button::-moz-focus-inner
{
    border:0;
    padding:0;
}
To complete the redirect <button>click here</button>.

Edit: The trick for removing padding in FireFox was taken from here

Edit2: Made button inherit font style from parent element to make it look like a valid link (previously font size and font family was different for the button).

like image 41
jahu Avatar answered Oct 02 '22 15:10

jahu


Try this:

<style type="text/css">
    .text-button 
    { 
        background-color: Transparent;                 
        text-decoration: underline;                 
        color: blue;
        cursor: pointer; 
        border:0
    }    
</style>
<input type="submit" class="text-button" value="vote+"/>
like image 43
Chandu Avatar answered Oct 02 '22 14:10

Chandu


IMO I guess I am a difficult developer to deal with. I would suggest to the person(s) requesting this application the option of just letting it remain a button?

Have you/they considered the following?

  1. Is it best practice from a UI standpoint to use something other than a button to submit a form?
  2. If you do go with the CSS approach, I don't believe Safari will allow you to change to look of a button.
  3. If you use the <a> tag with some javascript, then you have a form without a submit button, which may cause headaches in the future. How do you detect your submit link from your other <a> tags easily?
like image 27
Doug Chamberlain Avatar answered Oct 02 '22 15:10

Doug Chamberlain


I believe the answer submitted above by mofolo is the more correct solution

CSS styling of submit buttons to make them look like anchor tags does NOT cross browser. The text-decoration:underline style is ignored by many browser types.

The best method in my experience is to use javascript on an anchor tag's onclick event.

For example:

A "Delete" link on a user details form screen, with confirmation before submitting the form with an id of "userdetails"

<a href="#" onclick="if(confirm('Are you sure you want to delete this user?')){document.forms['userdetails'].submit();}return false;">Delete</a>
like image 22
SyntaxGoonoo Avatar answered Oct 02 '22 13:10

SyntaxGoonoo