Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Concatinating database fields in a drop down box

Status
Not open for further replies.

cwolgamott

Programmer
May 29, 2002
69
US
Hello. :) I am having great difficulty in figuring out how to create a drop down box (or menu) by concatinating two database fields, and then trying to pass the selection to another ASP page. Here is the code I use to create the drop down:

if NOT rs.eof then
rs.movefirst
nameArea = nameArea + &quot;<SELECT NAME=full_name>&quot;

Do until rs.eof
nameArea = nameArea + &quot;<OPTION VALUE=''>&quot; + rs(&quot;first_name&quot;) + &quot; &quot; + rs(&quot;last_name&quot;)
recCounter = recCounter + 1
rs.movenext

Then, on the page I am trying to pass it to, I use this code to assign it to a variable:

inputFullName = rs(&quot;full_name&quot;)
After that, I try to use it in the WHERE clause in my select statement. The only catch is, I need to compare the first_name that was put into the drop down with a first_name field and the last_name that was put into the drop down with a last_name field. In other words, I need to pass these values separately. I have tried everything that I can think of. I would greatly appreciate any suggestions that I can get. :) Thank you. :)
 
you can split the form data into the two parts first name and last name:

dim arrFNLN
dim strFN
dim strLN
inputFullName = &quot;John Smith&quot;
arrFNLN = Split(inputFullName, &quot; &quot;)

If UBound(arrFNLN) = 1 Then
strFN = arrFNLN(0)
strLN = arrFNLN(1)
end if
 
Hello. :) Thank you so much for your reply. :) I really appreciate it. I tried the coding that you gave me, but it does not seem to bring back any data. Here is coding that I am using to build the drop down:

SQL = &quot;Select &quot;
SQL = SQL + &quot;first_name + ' ' + last_name as fullname From Employees&quot;
SQL = SQL + &quot; ORDER BY first_name ASC&quot;

rs.movefirst
nameArea = nameArea + &quot;<SELECT NAME=fullname>&quot;

Do until rs.eof
nameArea = nameArea + &quot;<OPTION VALUE=''>&quot; + rs(&quot;fullname&quot;)
recCounter = recCounter + 1
rs.movenext

Then, I tried this coding on the page that I want to pass the name to:

inputFullName = Request(&quot;fullname&quot;)

arrFullName = Split(inputFullName,&quot; &quot;)

If UBound(arrFullName) = 1 Then
strFN = arrFullName(0)
strLN = arrFullName(1)
End If

SQL = &quot;Select &quot;
SQL = SQL + &quot;last_name, first_name, email, extension, userid, work_site FROM Employees WHERE &quot;
SQL = SQL + &quot;first_name=&quot; & &quot;'&quot; & strFN & &quot;'&quot; & &quot; AND last_name=&quot; & &quot;'&quot; & strLN & &quot;'&quot;

I just cannot seem to figure out where I am going wrong. I would greatly appreciate any suggestions or help. :) Thanks again. :)


 
Example:


<BODY>
<form action=&quot;ASP.asp&quot; method=post>
<select name=&quot;fullname&quot;>
<option value=&quot;John Smith&quot;>John Smith
<option value=&quot;John Smith1&quot;>John Smith1
<option value=&quot;John Smith2&quot;>John Smith2
</select>
<input type=Submit>
</form>

</BODY>



file ASP.asp:


Dim arrFNLN
Dim strFN
Dim strLN
Dim inputFullName
inputFullName = Request.Form(&quot;fullname&quot;)
arrFNLN = Split(inputFullName, &quot; &quot;)
If UBound(arrFNLN) = 1 Then
strFN = arrFNLN(0)
strLN = arrFNLN(1)
End If
Response.Write strFN & &quot;:&quot; & strLN



the above code works fine for me.
 
The value of your select is not set, only the innerHTML of the option instances of the select, this can only be used in client script.
You should write your option like so:

&quot;<OPTION VALUE='&quot; & rs(&quot;fullname&quot;) & &quot;'>&quot; + rs(&quot;fullname&quot;)


You will have a problem if someone's got the ' in their name.
You can replace this ' with the text in the following line please remove the spaces.
& # 3 9 ;
 
Thank you so much harmmeijer and sjravee for all of your help and suggestions. :) I appreciate it so much. :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top