Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
0

How to Dynamically Set the Value of a Hidden Field

New Here ,
Jul 11, 2006 Jul 11, 2006

Copy link to clipboard

Copied

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?
TOPICS
Server side applications

Views

553
Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 11, 2006 Jul 11, 2006

Copy link to clipboard

Copied

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)"

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 12, 2006 Jul 12, 2006

Copy link to clipboard

Copied

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)"



Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jul 12, 2006 Jul 12, 2006

Copy link to clipboard

Copied

LATEST
You need to write a script to calculate your form values and then the script
will submit the form.


"esonline" <webforumsuser@macromedia.com> wrote in message
news:e92nla$jg5$1@forums.macromedia.com...
>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)"
>

>
>
>


Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jul 12, 2006 Jul 12, 2006

Copy link to clipboard

Copied

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

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines