What's the point of having hidden input in HTML? What are common uses for this?

后端 未结 12 1147
无人共我
无人共我 2020-12-01 14:51

I don\'t see the benefit of having hidden input? If you set the value of the hidden input why not just use that value at the point where you reference this hidden input?

12条回答
  •  借酒劲吻你
    2020-12-01 15:12

    The hidden input is for when you want to send information back on a post without the user seeing the data as a UI element.

    The web is stateless - ergo, when a POST comes in, you have only a couple pieces of information to determine what you need to do; Session, Url, some ServerVariables, and the Form data passed to you.

    If a piece of data is transient that is not useful for putting in the session, sometimes it is prudent to put into a hidden field.

    They can also be useful for storing data on the client side for rich internet applications (such as a product Id that is easily accessible to use in ajax calls).

提交回复
热议问题