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

Jérôme Verstrynge picture Jérôme Verstrynge · Dec 19, 2011 · Viewed 9.8k times · Source

Input fields are usually associated to forms, but I would like to use them in a simple Javascript/HTML page. I don't need the form. I see no issue with my HTML page, but is there any danger or bad practice I am not aware of? I just don't want my page to bug down the road.

(Basically, a field in my page can be Javascript enabled or disabled according to values in other fields)

Answer

nnnnnn picture nnnnnn · Dec 20, 2011

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.