Webmasters Stack Exchange is a question and answer site for pro webmasters. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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"/> 
share|improve this question
up vote 2 down vote accepted

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"/> 
share|improve this answer
"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 '10 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...

share|improve this answer
I am using JSP can you demonstrate? – Amen Nov 17 '10 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 '10 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 '10 at 16:02

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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