Is there any danger to using input fields outside/without forms in HTML/Javascript pages?

The only real problem is if you want your page to function for users who have JavaScript disabled - if the inputs are actually for user input then placing them outside a form means that you'd need to use JavaScript (presumably with Ajax) to do anything with the values, whereas form fields can be submitted without JavaScript. If your page isn't intended to be submitted to the server anyway then you're dependent on JavaScript for interaction. If you've taken that into account and it doesn't matter for your scenario then go ahead.

P.S. I should've mentioned that as far as HTML standards go it is perfectly valid to have input elements that aren't in forms.


You should be fine AFAIK. It's ok in the HTML 4.01 standards anyway

http://www.w3.org/TR/html401/interact/forms.html#form-controls

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.


You can use an HTML validator (here, or on many other sites) to check this sort of thing. If it shows up legal, which I think it should in this case, as Ted pointed out, then you are probably good.