input type="text" value="5". I enter some text like(abc) in textbox . I needed to store text in database with id 5. So i needed value in hidden mode. How to make value in hidden mode.
Add an additional field to the page. In this example the first is the normal text field, the second will be hidden and will not show up:
<input type="text" value="" name="text" />
<input type="hidden" value="5" name="id" />
Then on the server, access both text
and id
to save. In PHP it would look like this:
$text = $_POST['text'];
$id = (int)$_POST['id'];
Be aware that this is easy to tamper with on the client side, so be sure to do whatever tests are necessary on the server to make sure it wasn't hacked.
Doug Neiner's answer is the preferred method, however as an ALTERNATIVE, if your fields are dynamically generated, you could do what SO does, which is incorporate the ID# into the id
attribute and then parse, such as id="myText-1234
where 1234
is the id you want to pass. Then you can split()
the id of the text box by "-" and grab the id, so long as your convention remains consistent.