Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTML input field OUTSIDE of a form

I have a form with a set of inputs, and I want my page to refresh when one of them changes. I have a second set of inputs on the OTHER side of the page, and the css layout doesn't make it convenient for me to put them in the same <form> </form> tag. I was wondering if there is a way that I can make sure those "inputs" that are located outside of the <form> tag are still associated with that form.

Is there some way we can assign a "form id" to the inputs?

like image 524
dlitwak Avatar asked Jul 10 '11 22:07

dlitwak


2 Answers

In HTML5, you can use the form attribute:

A form-associated element is, by default, associated with its ancestor form element, but may have a form attribute specified to override this.

If a form-associated element has a form attribute specified, then that attribute's value must be the ID of a form element in the element's owner Document.

Example:

<form id="myform">
    <input id="something" type="text">
</form>

<button form="myform" type="submit">Submit that form over there</button>

You should however make sure that it is clear to the user that these visually separated form elements are in fact connected.

like image 194
You Avatar answered Nov 10 '22 08:11

You


<input type="text" form="myform" /> worked for me.

Update
This worked great with FireFox, however gave me trouble in IE 11 as the form attribute is not recognized with IE (as of writing this).

I had to just set a hidden input field inside the form, and transferred value to hidden input field from input outside form; with onclick using jQuery.

like image 37
eaglei22 Avatar answered Nov 10 '22 09:11

eaglei22