Can an html form be split up all over a document just as long as the form names are consistant? Like this:
<form name="add_user">
<!-- textbox here -->
</form>
<form name="add_user">
<!-- another textbox here -->
</form>
<form name="add_user">
<!-- submit button here -->
</form>
[solved] Split up an HTML form?
Moderator: General Moderators
[solved] Split up an HTML form?
Last edited by dallasx on Thu Nov 10, 2005 3:17 pm, edited 1 time in total.
If you really want to do that, for the sake of source-code clarity, you can try the following:
Head:
Body:
And then somewhere on your page, you put this:
or
It's really a matter of choice, unless you want to use images in your button, in which case you have to use <button></button>.
Cheers,
Tom
Head:
Code: Select all
<script type="text/javascript">
function submit_all_forms () {
var form, field; //Used for iteration
var input; //Your temporary & 'virtual' input field
var forms = document.forms; //All forms on your page
var dynfrm = document.getElementById('dynform'); //Get the dynamic form from
for (form in forms) { //Cycle thru all forms
for (field in form.elements) { //Cycle thru all fields in each form
/* Create a new field dynamically */
input = document.createElement('input');
/* Set name & value attributes */
input.setAttribute('name', field.name);
input.setAttribute('value', field.value);
/* Insert the field into the dynamic form */
dynfrm.appendChild(input);
}
}
}
</script>Code: Select all
<!-- The following in crucial: -->
<form id="dynform" method="POST" action="some_script.php" style="display:none;"></form>
...some html...
<form ... name="frm1"></form>
...some more html...
<form ... name="frm2"></form>
...more html...
<form ... name="frm3"></form>
...more html...Code: Select all
<input type="button" value="Submit" onclick="submit_all_forms();" />Code: Select all
<button onclick="submit_all_forms();">Submit</button>Cheers,
Tom
- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia
Hmmm.... what do you need to split the form up for? You could always just have the <form></form> tags spaced out over the document.
EDIT | Well I guess with fancy CSS and positioning, if you have multiple forms on a page they could get tangled up. Perhaps they can nest inside one another... I've never tried nesting forms
EDIT | Well I guess with fancy CSS and positioning, if you have multiple forms on a page they could get tangled up. Perhaps they can nest inside one another... I've never tried nesting forms