Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New Coder
    Join Date
    Jul 2004
    Posts
    24
    Thanks
    0
    Thanked 0 Times in 0 Posts

    ASP Code doing one thing but not another.

    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:

    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
    Last edited by fishbone34; 08-24-2004 at 09:08 PM.

  • #2
    Senior Coder Morgoth's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada Remaining Brain Cells: 6
    Posts
    1,402
    Thanks
    2
    Thanked 1 Time in 1 Post
    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.
    Code:
    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.

  • #3
    New Coder
    Join Date
    Jul 2004
    Posts
    24
    Thanks
    0
    Thanked 0 Times in 0 Posts

    ...Detailed Problem Description

    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


    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
    %>

    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!
    Last edited by fishbone34; 08-24-2004 at 09:23 PM.

  • #4
    Senior Coder
    Join Date
    Jun 2002
    Location
    Wichita
    Posts
    3,880
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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:

    Code:
    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.
    Check out the Forum Search. It's the short path to getting great results from this forum.

  • #5
    New Coder
    Join Date
    Jul 2004
    Posts
    24
    Thanks
    0
    Thanked 0 Times in 0 Posts

    You are the MAN!

    It worked like a charm!

    Thanks again!


    Chris

  • #6
    Senior Coder Morgoth's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada Remaining Brain Cells: 6
    Posts
    1,402
    Thanks
    2
    Thanked 1 Time in 1 Post
    I understand what you mean now. It was a little confusing before, I didn't know what you meant by:
    Quote Originally Posted by fishbone34
    It displays properly in the drop down box but inputs into the MS-SQL database with just the "last_name"
    Good work Roy Sinclair.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •