开发者

What is the point of input without name in HTML5?

In HTML5, an input without name is also vali开发者_如何学编程d

e.g.

      <input type="text" id="user"  />

But what is the point if I cannot access the form element in my backend PHP code?


Not all input is used server-side. In many cases it's used for form submission via AJAX. Additionally, a JavaScript app can make use of user input without ever needing to use a form.


Click the "link" button on any question or answer here on Stack Overflow, you will see an example of an <input> without a name or associated form.

Granted, this particular input is created with javascript - but it's pretty common to see an input field or textarea for copy/paste purposes, for one example.

..and it's also useful for basically anything to do with javascript.

One non-AJAX example I am currently using:

I have a spreadsheet for several dollar amounts to be filled in. I use an <input> field with no name to display the total amount of each column with javascript. On the server side, I don't need a "total amount" field coming through, and I sure as hell wouldn't trust it. The real total amount is calculated on the server side based on the other inputs, but we still show it in real time on the front end for the user.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜