Basic Syntax:
<input type= "hidden" name= "Field_name" value= "value" >
function:
1 hidden fields are not visible to users in the page, and the purpose of inserting hidden fields in a form is to collect or send information for use by the program that processes the form. When the browser clicks the Send button to send the form, the hidden field information is also sent to the server.
2 Sometimes we have to give the user a message to submit the form to determine the user's identity, such as SessionKey, and so on. Of course, these things can also be implemented with cookies, but the use of hidden fields is much simpler. And there will be no browser is not supported, the user to disable cookies annoyance.
3 Sometimes there are multiple commit buttons in a form, how can the program be able to tell if the user is submitting a button? We can write a hidden field, and then add onclick= "document.form.command.value=" xx at each button and then check the command value before we receive the data and we will know that the user is pressing the button to submit it.
4 Sometimes there are multiple form in a Web page, we know that multiple form can not be submitted at the same time, but sometimes these form do interact, we can add hidden fields in the form to make them relate.
5 JavaScript does not support global variables, but sometimes we have to use global variables, we can put the value in the hidden field first, its value will not be lost.
6 There is another example, such as pressing a button to pop up four small windows, when you click on one of the small window, the other three automatically closed. However, IE does not support small windows to call each other, so only in the parent window to write a hidden field, when the small window to see that the value of the hidden field is close when you turn off.
Example: Using hidden to implement the Click submit button number plus 1
Numeric increment. htm
The code is as follows:
<form action= "Numeric increment. ashx" method= "POST" >
<input type= "hidden" name= "_viewstate" value= "a"/>
<input type= "hidden" name= "_div" value= "@n"/>
<!--<input name= "txt" type= "text" value= "@value"/>-->
<div>@n</div>
<input type= "Submit" value= "click"/>
</form> using Generic handler implementations
The value is self-increasing. Ashx
The code is as follows: int n = 0;
public void ProcessRequest (HttpContext context) {
Context. Response.ContentType = "text/html";
String path = context. Request.mappath ("value from increment. htm");
String html = System.IO.File.ReadAllText (path);
Determines whether the page is loaded for the first time
String viewstate = Context. request.form["_viewstate"];
if (!string. IsNullOrEmpty (ViewState))
{
Click the button Post
Get the value of a hidden field
string s = context. request.form["_div"];
if (int. TryParse (S, out N))
{
n++;
html = HTML. Replace ("@n", n.tostring ());
}
}
Else
{
The first time the page is loaded, assign values to the hidden fields for div and div
html = HTML. Replace ("@n", n.tostring ());
}
Context. Response.Write (HTML);
}
Hidden fields in HTML hidden