1

If I am writing an application where I can dictate that the users must have a modern browser with javascript enabled, what is the benefit of using the html tag.

For instance if I submit all of my "forms" by doing something like this, but I don't actually have any form tags in my html. I just build a datalist to pass through the data parameter of the $.ajax call

$('#submit_form').click(function(){
   var datalist='foo='+$('#foo').val();
   $.ajax({
     // ajax json here
   });
}

Why would I use the form tag in my html code? I am sure there is probably a good reason, but a friend asked me the other day and I couldn't give him a good reason why it was needed.

5
  • If you don't need a form, either as a fallback or to serialize the data or for validation or anything else a form can be useful for, there's no reason to use a form. Commented Jan 20, 2014 at 19:09
  • Forms are optional -- you don't have to use them unless you specifically want to refer to items within the form and handle a form like a form... Commented Jan 20, 2014 at 19:10
  • The only other reason I can think of is that I'm not sure if validators kick up a fuss if they find input tags that are not contained within a form tag. If that sort of thing is important to your app, that could be a concern. Commented Jan 20, 2014 at 19:11
  • Don't you need a <form> in order to post a file (<input type="file" />)? Commented Jan 20, 2014 at 19:13
  • @DavidHoerster : I think you can post a file from an AJAX call without the <form> element. However, for fallback purposes you might want an actual form, though the OP has specified he's requiring his users to have a modern browser with JS enabled. Commented Jan 20, 2014 at 19:20

2 Answers 2

1
  1. Your server side fallback will cause the form to continue to work if the JavaScript fails for some reason other than "the user has turned it off" (such as a network interruption)
  2. Having the fields logically grouped in a form will make them more easily navigable in most screen reader software.
Sign up to request clarification or add additional context in comments.

4 Comments

1. Can you tell me more about how network interruption may play a role? 2. What is a screen reader software?
1. For example, user is on a train and enters a tunnel while downloading the page. The Internet connection drops, the JavaScript file doesn't download. 2. Screen readers read out content and describe UI controls over headphones/speakers so people with vision related disabilities can still use computers.
Thanks for the response. I understand about screen readers and that is a great point. Tell me more about the Network Interruption. I mean if a connection is lost, you not going to get much done on a website that doesn't use javascript either. In your experience would you recommend to always use forms even if I can save some time by not using them.
If the network is lost momentarily then it can trash an attempt to load a file, and if that file is JS or CSS then, if the site is well designed it will still be usable. Yes, use forms, skipping them isn't going to save you a significant amount of time.
1

that and also you can use the html 5 attribute such as "required" (not submitting the form if this field empty)

<input type="text" required = required />

or <input type="email"/> (make sure its a valid email address). without a form this attribute will not work. with this code you save a bunch of code in JS.

hope i helped.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.