Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Original purpose of <input type="hidden">? [closed]

I am curious about the original purpose of the <input type="hidden"> tag.

Nowadays it is often used together with JavaScript to store variables in it which are sent to the server and things like that.

  • HTML 2.0 was released in November 1995, containing already the specification for input type="hidden"
  • JavaScript was released March 1996

Therefore, the <input type="hidden"> existed before JavaScript, so what was its original purpose? I can only imagine of sending a value from the server to the client which is (unchanged) sent back to maintain a kind of a state. Or do I get something wrong in the history of it and <input type="hidden"> was always supposed to be used together with JavaScript?

If possible, please also give references in your answers.

like image 696
Uooo Avatar asked Apr 30 '13 06:04

Uooo


People also ask

Is input type hidden safe?

Since they are not rendered visible, hidden inputs are sometimes erroneously perceived as safe. But similar to session cookies, hidden form inputs store the software's state information client-side, instead of server-side. This makes it vulnerable.

Do hidden inputs get posted?

Show activity on this post. Yes, they'll get submitted unless they are removed from the document or have the disabled attribute set on them.

How do you find the input type hidden value?

#3 jQuery Code To Get hidden field value by typevar getValue= $("input[type=hidden]"). val(); alert(getValue); Here in the above jquery code, we select input hidden filed by its type i.e hidden, and then by using jquery . val() we get the hidden field value.

What is hidden form?

Hidden form field is used to store session information of a client. In this method, we create a hidden form which passes the control to the servlet whose path is given in the form action area. Using this, the information of the user is stored and passed to the location where we want to send data.


2 Answers

I can only imagine of sending a value from the server to the client which is (unchanged) sent back to maintain a kind of a state.

Precisely. In fact, it's still being used for this purpose today because HTTP as we know it today is still, at least fundamentally, a stateless protocol.

This use case was actually first described in HTML 3.2 (I'm surprised HTML 2.0 didn't include such a description):

type=hidden
These fields should not be rendered and provide a means for servers to store state information with a form. This will be passed back to the server when the form is submitted, using the name/value pair defined by the corresponding attributes. This is a work around for the statelessness of HTTP. Another approach is to use HTTP "Cookies".

<input type=hidden name=customerid value="c2415-345-8563"> 

While it's worth mentioning that HTML 3.2 became a W3C Recommendation only after JavaScript's initial release, it's safe to assume that hidden fields have pretty much always served the same purpose.

like image 116
BoltClock Avatar answered Oct 19 '22 04:10

BoltClock


I'll provide a simple Server Side Real World Example here, say if the records are looped and each record has a form with a delete button and you need to delete a specific record, so here comes the hidden field in action, else you won't get the reference of the record to be deleted in this case, it will be id

For example

<?php     if(isset($_POST['delete_action'])) {         mysqli_query($connection, "DELETE FROM table_name                                     WHERE record_id = ".$_POST['row_to_be_deleted']);                                    //Here is where hidden field value is used     }      while(condition) { ?>     <span><?php echo 'Looped Record Name'; ?>     <form method="post">         <input type="hidden" name="row_to_be_deleted" value="<?php echo $record_id; ?>" />         <input type="submit" name="delete_action" />     </form> <?php     } ?> 
like image 37
Mr. Alien Avatar answered Oct 19 '22 06:10

Mr. Alien