Friday, May 10, 2024
 Popular · Latest · Hot · Upcoming
86
rated 0 times [  92] [ 6]  / answers: 1 / hits: 16314  / 13 Years ago, fri, june 10, 2011, 12:00:00

Philosophical question:



Say I've got a web app that requires javascript and a modern browser, so progressive enhancement is not an issue. If my form is being built via javascript, and my data updates are all being done via ajax POSTs & PUTs, is there really any reason to wrap my controls in a form tag? If I'm still going to use the tag, say for semantic or structural reasons, is there any reason to have action and method params that I'm going to ignore? It kind of feels like a hold-over from an earlier era to me.


More From » html

 Answers
148

There is at least one important user-experience feature provided specifically by wrapping inputs inside a form tag:



The enter key will submit the form. In fact, in Mobile Safari, this is how you get the Go button to appear on the keyboard.



Without a form wrapping the inputs, there is nothing to submit.



You can of course provide enter-key behavior through a keypress event, but I don't know about if this works for mobile devices. I don't know about you, but I'd rather work with the semantics provided by the browser than have to imitate them with events.



In your case, you would simply provide an onsubmit event handler for the form, which would do your AJAX submit, then return false, canceling the actual submit.



You can simply provide action= (which means self), and method is not required — it defaults to GET.


[#91767] Thursday, June 9, 2011, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
wilson

Total Points: 27
Total Questions: 93
Total Answers: 93

Location: Tajikistan
Member since Sun, Aug 29, 2021
3 Years ago
wilson questions
Tue, Aug 9, 22, 00:00, 2 Years ago
Wed, May 11, 22, 00:00, 2 Years ago
Wed, May 20, 20, 00:00, 4 Years ago
Wed, May 13, 20, 00:00, 4 Years ago
;