Why would you have a button inside an <a> anyway? That sounds like an accessibility foul-up from the word go.
A button should be used to initiate an action via the server, such as a form submission.
A hyperlink should be used to navigate to another page or a client-side action (eg Javascript).
I can’t think of any situation where putting a <button> inside an <a href> would be the right way of doing things (although I’m open to being corrected on that). If you want the look of a button for your hyperlink, you’re better off recreating that look with CSS applied to text, or an image.
Well I can’t use a form submit button because forms can’t be inside a table. I basically just want a submit button that sends GET variables without the form.
If I don’t use <a href> then the button does nothing. How do I make the button active with a specified link?
Yes, I could just use a link without the button but the button looks nicer which is why I was trying to use the button as a link instead of text.
What would be the point of <input type=“button”> if we can’t wrap it in a link?
Am I supposed to use onclick=“” to make it work?
If so, (my JavaScript is awful at the moment) how do I implement two functions into the onclick=“” part? For example, I want it to give me the confirmation for the delete function and then actually navigate somewhere if confirmed.
<script type="text/javascript">
<!--
function confirmDelete() {
var vReply = confirm("This item will be deleted. Continue?")
if (vReply){
window.location = "page-to-handle-delete.html";
}
else{
// If needed, you can take action here when the Cancel button is clicked...
// alert("Your item was NOT deleted.")
}
}
//-->
</script>
As always, be sure to code defensively to warn your visitors that JavaScript is needed for the page to function correctly. There are still a few people that are browsing like it’s 1996.
Because it offers more styling options than a regular Submit/Cancel type <input>.
How about … because it will ruin the accessibility of the site, meaning that anyone not running Javascript can’t access the service, including a fair proportion of people using mobile phone browsers.
Pretty much - <input type=“button”> doesn’t actually do anything, so needs to paired up with Javascript to make it useful. A better solution might be to use <button type=“submit”>, which (I think!) gives you the same styling advantages, but means that the form action is called when the button is clicked on, which makes it a more useful setup.
HTML5 doesn’t validate if a <form> tag is within a <table> tag. I haven’t actually read the specification so I’m not 100% sure.
At its simplest, all I wanted to do was use the button instead of blue link text to link somewhere and thought I could replace the text with the input tag.
I was trying to keep it all HTML and didn’t want to use CSS or JS if it wasn’t necessary which I’ve learned is not the case.
Which is why I posted the disclaimer about defensive coding and handling users that have JS disabled. We do not know if this page is public facing or for a closed intranet where the browsers and capabilities are known. The OP will need to make that assessment and handle accordingly.
It’s mainly to keep central administration to a low. We can keep IE updated through GPOs and not have to worry about users not being able to install the latest Firefox update. Also, users tend to install every toolbar out there somehow and we can prevent this easily this way.
I would love to deploy Chrome with its silent background updates; However, that is not my decision to make.
It seems to me that you can simply put your anchor tag around an image of a button, no? This would give you the appearance of a button, yet it acts like a link.