Hidden field with variable problem

T

Tom Petersen

Here is the code:
<SELECT NAME="email" style="font-family: Verdana; font-size: 10pt; "
size="1">
<%
DO WHILE NOT objRS.EOF
strEmail = objRS("email")
strLName = objRS("last_name")
strFName = objRS("first_name")
%>
<option value="<% =strEmail %>"><%= strLName & ", " & strFName %>
</option>
<%
objRS.MoveNext
Loop

objRS.Close
Set objRS = Nothing

%>

</SELECT></font></b></td>
<input type="hidden" name="last_name" value="<% =strLName %>">

snip

<INPUT TYPE=SUBMIT VALUE="Submit Form">


Now when the form is submitted to my results page that updates the database,
the value for strLName is, obvioulsy, the last record in the database. How
do I make the value equal what the user selected from the drop down?

Or in other words, if my drop down value is:
1
2
3
4
5,
and the user picks 3, the value that gets added to the db is always 5...

TIA
 
R

Ray at

Easiest way that wouldn't rely on client side coding would be to do:


<option value="<%=strEmail & "," & strLName%>"><%= strLName & ", " &
strFName %></option>


Then on the page that processes this data, the value of
request.form("email") would be something like:

(e-mail address removed),Bergey

So, you can then do

aEmailInfo = Split(REquest.Form("email"), ",")
sEmail = aEmailInfo(0)
sLName = aEmailInfo(1)


Basically, you have to pass the last name in a form field. But let me ask
you this. If the info is coming from the database, why do you need to do
this? Isn't this person's information already in the database? Like, it
seems that if I were in your database, I could tell you my e-mail address,
and you could then in turn tell me my last name, so why do you need to
update this column like this?

Ray at work
 
T

Tom B

The value of your select is not the strLName it's the strEmail.
Why do you want to use a hidden field?
You shouldn't use strEmail as a unique value, my wife and I share an email
account?

I'll assume that you know what you're doing and the above is my error.
What you'll need to do is either a)re-query the database based on the
selected email or b) parse out the last name from the content of the
<select> on the client, and update your hidden form.
To do "b" would require some client side scripting such as javascript.
 
T

Tom Petersen

I think I am confusing myself!
I have two databases, one already contains email, last_name and first_name.
My problem is updating the second database with all of the same fields when
my form is only 'collecting' the email. So can I still use your method if I
also need the first name, how does the Split work if I 'need' a second
comma?

Or should I use Tom B's suggestion and grab the info I need from database
base 1 using a query like Select last_name, first_name from xxx Where email
= request.form(email), using the correct syntax of course... Whic do you
think would be better?

Thanks!
 
R

Ray at

Tom Petersen said:
I think I am confusing myself!
I have two databases,
Eegs!

one already contains email, last_name and first_name.
My problem is updating the second database with all of the same fields when
my form is only 'collecting' the email. So can I still use your method if I
also need the first name, how does the Split work if I 'need' a second
comma?

You can have as many commas as you like, or you can use any character.
Split() will create an array by splitting the string on whatever
character(s) you specify. For example:

TheString="(e-mail address removed)|Costanzo|Ray"
TheSplitStringArray = Split(TheString, "|")

You'll then have an array with three elements:
TheSplitStringArray(0) = "(e-mail address removed)"
TheSplitStringArray(1) = "Costanzo"
TheSplitStringArray(2) = "Ray"




Or should I use Tom B's suggestion and grab the info I need from database
base 1 using a query like Select last_name, first_name from xxx Where email
= request.form(email), using the correct syntax of course... Whic do you
think would be better?

I would use Tom's suggestion of NOT using e-mail addresses as your unique
identifier. Let's assume your data in database1 looks like this:

ID Email LName Fname

What you should do then is use the ID number in your SELECT, and when the
person selects the value and submits the form, query the e-mail address,
last name, and firstname from database1 and do what you have to do with it
in database2 then.

Ray at work
 
T

Tom Petersen

Ray,
That did it, thanks!

Tom B, thanks for chiming in as well, I went the parse route, and learned
about the Split 'command'
 
T

Tom Petersen

Dan, good call, didn't even think of that, but I did get what I needed
working, so I'm not going to touch it! :)
 
D

Dan Brussee

Easiest way that wouldn't rely on client side coding would be to do:


<option value="<%=strEmail & "," & strLName%>"><%= strLName & ", " &
strFName %></option>


Then on the page that processes this data, the value of
request.form("email") would be something like:

(e-mail address removed),Bergey

So, you can then do

aEmailInfo = Split(REquest.Form("email"), ",")
sEmail = aEmailInfo(0)
sLName = aEmailInfo(1)


Basically, you have to pass the last name in a form field. But let me ask
you this. If the info is coming from the database, why do you need to do
this? Isn't this person's information already in the database? Like, it
seems that if I were in your database, I could tell you my e-mail address,
and you could then in turn tell me my last name, so why do you need to
update this column like this?

Ray at work
Or, of course (assuming you have a unique ID for your records) just
use the ID as the value and look up what you need using a query on
that ID field.
 
R

Ray at

Quote from another reply: What you should do then is use the ID number in
your SELECT
:p

Ray at work
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,094
Messages
2,570,615
Members
47,231
Latest member
Satyam

Latest Threads

Top