Casa > H > How To Make Submit Button Without Form

How to make submit button without form

HTML5

In HTML5, a has a form attribute. See 4.10 Forms - HTML5.

The form attribute is used to explicitly associate the button element with its form owner.

Example

  1.  
  2.  
  3.  
  4.  
  5. Submit 

The problem is that doesn't work on IE.

HTML4

Since submit button is a type of control, the submit must appear inside a

. See Forms in HTML documents.

The elements used to create controls generally appear inside a FORM element, but may also appear outside of a FORM element declaration when they are used to build user interfaces. This is discussed in the section on intrinsic events. Note that controls outside a form cannot be successful controls.

That said, we can try some things.

Label Element

Something you can do is hide the submit inside a

, and then associate a outside of it. When you click on the text within the element, it toggles the button.
  1.  
  2.  
  3.  
  Submit 

But, you can't select the with tab and press space to select, for users that is using the keyboard to naviagate.

JavaScript

You can use JavaScript onclick event.

  1.  
  2.  
  3.  
  4.  
  5. Submit 
  6.  
  7. document.getElementById("submit-button").onclick = function() { 
  8. document.getElementById("form1").submit(); 
  9.  

De Ike

Posso carregar jogos a vapor com um cabo para o Oculus Quest 2? Se sim, tenho de manter o cabo ligado enquanto estou a jogar? :: A Apple realmente valoriza a privacidade dos dados?