Skip to main content
Known Participant
July 12, 2006
Question

How to Dynamically Set the Value of a Hidden Field

  • July 12, 2006
  • 2 replies
  • 595 views
I have an insert form and would like to control the value that is inserted for the Primary Key field of the databse. To do this i have inserted a Hidden Field which value will be used for the Primary Key of the databse.

Now what I would like to do is to dynamically set the value of the hidden field when the form is submitted. Therefore when the record is inserted the value that i have calculated via code for the hidden field is insereted into the database.

I guess my question then is how do you dynamically set the value of a hidden field?
This topic has been closed for replies.

2 replies

Inspiring
July 12, 2006
On 11 Jul 2006 in macromedia.dreamweaver.appdev, esonline wrote:

> I have an insert form and would like to control the value that is
> inserted for the Primary Key field of the databse. To do this i
> have inserted a Hidden Field which value will be used for the
> Primary Key of the databse.
>
> Now what I would like to do is to dynamically set the value of the
> hidden field when the form is submitted. Therefore when the record
> is inserted the value that i have calculated via code for the hidden
> field is insereted into the database.
>
> I guess my question then is how do you dynamically set the value of
> a hidden field?

Skip the hidden field; do it serverside just before the insert. Anything
which relies on javascript is unreliable and can be spoofed, anyway.

Why do you want to use a key field with semantic value, anyway?

--
Joe Makowiec
http://makowiec.net/
Email: http://makowiec.net/email.php
Participating Frequently
July 12, 2006
What language?

In ASP, you can just assign the value you calculate to a variable, and in the hidden field, insert that value with the variable.
<%
DIM varMyVariable
varMyVariable = "Dog" & "Cat" 'sample assignment of a value
%>
Here's the input field.
<input name="hiddenField" type="hidden" value=<%=varMyVariable%> />

The value <%=varMyVariable%> is short way of doing "response.write(varMyVariable)"
esonlineAuthor
Known Participant
July 12, 2006
I understand except that I am not sure if this method will work for me since in my case the value of the hidden field is determined after the user has completed the other inputs on the form and has submited the form (in other words user has pressed the Submit button). After the form is submitted I use the values of several other non-hiddedn input fields to compose the value for the hidden field (which in reality is the value for the Primary Key.)

quote:

Originally posted by: DLoe
What language?

In ASP, you can just assign the value you calculate to a variable, and in the hidden field, insert that value with the variable.
<%
DIM varMyVariable
varMyVariable = "Dog" & "Cat" 'sample assignment of a value
%>
Here's the input field.
<input name="hiddenField" type="hidden" value=<%=varMyVariable%> />

The value <%=varMyVariable%> is short way of doing "response.write(varMyVariable)"