...

View Full Version : ASP Code doing one thing but not another.



fishbone34
08-24-2004, 05:50 PM
I have a Form that Post is not posting Last_Name, First_Name....It is only posting the LAST_NAME...

I have narrowed it down to the below code. The code is for pulling the Last_name and First_name from another table and populating my drop down box with "Last_name, First_Name" For my Agents. It displays properly in the drop down box but inputs into the MS-SQL database with just the "last_name"

Here is the part of my code were it pulls Last_Name, First_Name

MY CODE:


query1 = "Select Last_Name,First_Name from tb_Employee WHERE user_type IN ('Consultant','Tech') ORDER BY Last_Name ASC"
void = " "
agentNames = "<option value=" & void& ">" &void& "</option>"

set objRS=Conn.execute(query1)
while NOT objRS.EOF
theagent = (objRS("Last_Name") &", "&objRS("First_Name"))
agentNames = agentNames & "<option value=" &theagent& ">" &theagent& "</option>"
objRS.MoveNext
WEND
objRS.Close
conn.close
%>


________________


Thank you to anybody that can figure this out!


Chris
chris@thesouthside.net

Morgoth
08-24-2004, 07:27 PM
Please use code tags to display your code.

First off, it doesn't look like you keep your code very neat, so it will be hard to find the problem, when it could be just a simple missing variable, or space.
You also have some very unnecessary code, let's clean this up a bit.


Query1 = "SELECT Last_Name, First_Name FROM tb_Employee WHERE user_type IN ('Consultant','Tech') ORDER BY Last_Name ASC"
Set objRS=Conn.execute(query1)

AgentNames = "<option value= > </option>"
While NOT objRS.EOF = True
TheAgent = objRS("Last_Name") & ", " & objRS("First_Name")
AgentNames = AgentNames & "<option value=" & theagent & ">" & theagent & "</option>"
objRS.MoveNext
WEND
objRS.Close
conn.Close
%>


It looks like this code will work, unless your First_Name or Last_Name fields are blank. What exactly is your problem? I thought it was putting First_Name into a table, which this code does not even attempt.

fishbone34
08-24-2004, 08:11 PM
The problem is...

The Code fills in my Drop down boxes with this format:

LAST_NAME, FIRST_NAME


But when it updates the database...it's only the LAST_NAME



query1 = "SELECT Last_Name, First_Name FROM tb_Employee WHERE user_type IN ('Consultant','Tech') ORDER BY Last_Name ASC"
void = " "
agentNames = "<option value=" & void& ">" &void& "</option>"

set objRS=Conn.execute(query1)
while NOT objRS.EOF
theagent = (objRS("Last_Name") &", "&objRS("First_Name"))
agentNames = agentNames & "<option value=" &theagent& ">" &theagent& "</option>"
objRS.MoveNext
WEND
objRS.Close
conn.close
%>



My Drop down box populates from "agentNames".

Why would it populate my drop down box one way but when the form submits, it submits it another way?


I set it up to take the drop down box name="Agent"
and do a Response.Write(request.form("Agent")) and it always displays "Last_Name" and never what the dropdown box displayed through a Browser. (Last_name, First_Name)

>> Thanks!

Roy Sinclair
08-24-2004, 08:19 PM
It's the (missing) quote marks which make the difference.

Consider these two option fields:

<option value=Duck, Donald>Duck, Donald</option>

and

<option value="Duck, Donald">Duck, Donald</option>

Can you see why the first one is only going to send "Duck," as the value?

Guess which form you're creating with your code?

Try this:



agentNames = agentNames & "<option value=""" &theagent& """>" &theagent& "</option>"


The inline "" causes a single double quote mark to be included in the genrated string, it's """ in both cases in the example I gave because the inline quote we needed to add is adjacent to a quote mark denoting the end or the beginning of a string. Basically remember that anytime you need the output to contain a doublequote mark just double them up.

Make it your habit to always include quote marks for your HTML properties, and you'll not run into this kind of a problem again.

fishbone34
08-24-2004, 08:25 PM
It worked like a charm!

Thanks again!


Chris

Morgoth
08-24-2004, 08:43 PM
I understand what you mean now. It was a little confusing before, I didn't know what you meant by:


It displays properly in the drop down box but inputs into the MS-SQL database with just the "last_name"


Good work Roy Sinclair.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum