Submit a form using a tag tag

It is difficult to enter style data without using images or javascript.

As I know, there is no way to embed HTML directly in the sumbit input value. And if I complete the input to the div element (for example, to add a few borders), not all clickability will be available.

Will clicking on the shortcut cause the form to be submitted in all browsers ?

<form method="test.rb"> <input type="text" name="test" id="test" /> <label for="button"> <input type="submit" name="button" id="button" value="Send!" /> </label> </form> 
+4
source share
4 answers

According to W3C label binding :

The label element is not used for the following, because labels for these elements are provided through the value attribute (for the Submit and Reset buttons), the alt attribute (for the image buttons), or the element content itself (button).

Thanks to @Jeremiah Isaacson for pointing this out.


Old answer

Yes it will work. I cannot verify the behavior in all browsers, but here is what the W3C Specification should say :

To associate a label with another control implicitly, the control element must be in the contents of the LABEL element ... When the LABEL element receives focus, it passes focus on the corresponding control.

So, I think by clicking on the LABEL, you are essentially clicking on the input.

Thanks to @stevelove for pointing out the feasibility of this.

+6
source

If the problem is placing the HTML inside your button, you should use a <button> , which will allow you to do just that.

<button type="submit" name="button" id="button"><img src="button.png" />Send!</button>

But to answer your question about <label> : No, that will not work. Apparently, this will work, and, thinking, I see no reason why this should not.

+3
source

It is difficult to enter style data without using images or javascript.

It is very easy to style inputs without using javascript or images.

using the css style for all submit buttons - input[type=submit] or use the input.submit-btn class applied to specific elements

you can style the color, border, background, indentation, position, font weight, gradients, cast shadows ... the whole amount of effects using css ...

voila sexy button -

  input[type=submit] { padding:4px; color: #fff; margin-top: 10px; background-color: #e96000; border: none; background: -webkit-gradient(linear, 0% 0%, 0% 100%, from(#ff6900), to(#e96000)); background: -moz-linear-gradient(25% 75% 90deg, #e96000, #ff6900); -webkit-border-radius: 4px; -moz-border-radius: 4px; border-radius: 4px; } 
0
source

You can add any html element to the label and using this code, the entire label will work as a submit button.

  <form method="" name="myForm"> <input type="text" name="" placeholder=""> <label for="" class="" onclick="myForm.submit() "></label> </form> 
-1
source

All Articles