I want my submit button to be positioned somewhere that outside my form element? Do I have any options? With the exception of jquery.
Thanks, rodchar
For a HTML form element you can put your submit button outside of the form element as long as you have reference the form's id property with the button's form property.
A button element is valid anywhere in the document body where text-level markup may appear. Such an element need not have any relationship to a form element.
Submit buttons are placed at the bottom of the page to optimize top to bottom flow. There should always be two buttons, a primary action button that will commit changes made by the user and a Cancel button that will abort those changes.
The Submit Button The <input type="submit"> defines a button for submitting the form data to a form-handler. The form-handler is typically a file on the server with a script for processing input data. The form-handler is specified in the form's action attribute.
Another approach to this is merely to set the form
attribute on the button:
<form id="first">
<input type="submit" form="second" value="Submit Second" />
</form>
<form id="second">
<input type="submit" form="first" value="Submit First" />
</form>
Fiddle: http://jsfiddle.net/52wgc2ym/
Original Answer
The natural behavior of a submit button is to submit the nearest form up its hierarchy. The only other way to get a button to submit a form which it doesn't reside in is to use JavaScript (which is what jQuery is, basically).
If necessary, you could reposition the submit button so that it appears as though it's not in the form visually when the page is rendered. You would do this using CSS, which may give the desired result(s).
This is a common situation. I think this will do it (haven't tested it):
<form id="form1" action="someAction.cgi" method="GET">
<!-- other fields go here -->
</form>
<form id="form2" action="someOtherAction.cgi" method="GET">
<!-- other fields go here -->
</form>
<form>
<input value="Form One" type="button"
onclick="document.getElementById('form1').submit();"/>
<input value="Form Two" type="button"
onclick="document.getElementById('form2').submit();"/>
</form>
I'm not sure if you need that last <form>
. I seem to remember browsers ignoring events if the button wasn't in a form
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With