QNA > 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.  

Di Christmann Vanosdel

Cosa sono i CSS? Quali sono i diversi metodi per includere i CSS in un programma HTML? :: Qual è l'impatto dei social media sul diritto costituzionale alla privacy e alla libertà di espressione?
Link utili