I have the following fields:

First Name: <input type="text" id="tFName" name="tFName" maxlength="50" />
Last Name:  <input type="text" id="tLName" name="tLName" maxlength="50" />

Is the following the proper way to receive the values of the above fields in hidden inputs?

<input type="hidden" name="tFName" value="tFName"/>
<input type="hidden" name="tLName" value="tLName"/> 

3 Answers 3


Yes...if their first name is "tFName" and their last name is "tLName". A hidden field is just like a text field except that the user can't see the field or change it's value. So the value attribute of the <input> tag should be whatever value you wish to send to your server side script. If you need to change that information dynamically you can use JavaScript to update the value attribute as needed.


If you want to send the hidden first name of "John" and last name of "Conde" you would use this code:

<input type="hidden" name="tFName" value="John"/>
<input type="hidden" name="tLName" value="Conde"/> 
  • "A hidden field is just like a text field except that the user can't see the field or change it's value." - Not necessarily true so don't depend upon those hidden form input values; consider FireBug's live DOM editing capabilities and rogue bots. Use server-side sessions to store data across multiple page requests unless you know the data will be validated every time the form is submitted.
    – danlefree
    Nov 17, 2010 at 17:24

Do you mean the first example sends to a second page that stores them, or on the same page you want a text field and a hidden field, where the hidden field is set to the value entered in the text field?

Either way, this can't be done with pure HTML. You'll need to use a server side language like PHP/ASP/ColdFusion/etc. if you're trying to set the values.

PHP would do it like so...

// form page 1
First Name: <input type="text" id="tFName" name="tFName" maxlength="50" />

// form page 2
<input type="hidden" name="tFName" value="<?php $_POST['tFName']"/>

If you're trying to set it on the same page, you could try to call a javascript onsubmit() to take the value from the text field and then set it in the hidden field, then do a submit. I'd have to test this to see if it would work, but that's my first thought on it...

What's the purpose? That may help understand a better way to go too...

  • I am using JSP can you demonstrate?
    – Amen
    Nov 17, 2010 at 15:33
  • I am having the user enter info into the text fields and if they want to add that user into their contacts they have that option. So I was using the hidden fields to pass that info. I think the Javascript approach is the right one what do you think?
    – Amen
    Nov 17, 2010 at 15:42
  • If they've entered info in the text fields and you have a checkbox that says "Add to contacts [x]", couldn't you just take the info from text fields and add that to contacts?
    – digit1001
    Nov 17, 2010 at 16:02

Holy Cow, 13 years ago is a long time... but here goes nothing... The page 1 will be submitting its form to some server side controller method where you could write a little function to _get_data_from_post() and store it in a $data[] array which should be self explanatory, and then pass that array into the view that renders the page 2 form, where there should be a number of hidden input tags where the passed in $data[] array values serve as the value of each of the hidden input fields. Once you submit page 2 to the server-side controller method, you should be able to retrieve all of the values from both form pages, using $_POST.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.