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 derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Get 2 values from Dropdown ( 1 hidden)

Status
Not open for further replies.

streborr

IS-IT--Management
Jan 16, 2002
98
I have a dropdown box populated from a db.
What I need to know is if I can have two values in the option value, one sent to one field and another sent to a different field.

Example:

User chooses from a dropdown list on a form.
I need one value (which is visible in the list) to go to the "dist_name" field and a another value (dist_number) to go to the "dist_number" field when the user hit the submit button on the form.

The code below is what I have now. The list displays distributor name and city, when chosen the value(distributor name) is submitted.

<select size=&quot;1&quot; name=&quot;Dist&quot;>
<option value=&quot;&quot;>Select Distributor</option>
<%
Do while not rsADO.eof
Response.write &quot;<option value='&quot; & rsADO(&quot;dist_name&quot;) & &quot;'>&quot;
Response.write rsADO(&quot;dist_name&quot;) & &quot; - &quot; & rsADO(&quot;dist_city&quot;)
Response.write &quot;</option>&quot;
rsADO.MoveNext
Loop
rsADO.close
set rsADO = nothing
%>
</select>

Thanks,
Rick
 
You can put the values you need into the option with a delimiter like this:

Response.write &quot;<option value='&quot; & rsADO(&quot;dist_number&quot;) & &quot;|&quot; & rsADO(&quot;dist_name&quot;) & &quot;'>&quot;

Then when you submit, split the value into an array:
dist = Request.Form(&quot;dist&quot;)
tmp=Split(dist,&quot;|&quot;)
dist_number=tmp(0)
dist_name=tmp(1)

Then assign these variables to the appropriate textboxes as you would normally.
 
Would this be correct?

dist = request.form(&quot;dist&quot;)
tmp=Split(dist,&quot;|&quot;)
dist_name=tmp(0)
dist_number=tmp(1)
%>
<input type=&quot;hidden&quot; name=&quot;dist&quot; value=&quot;<% dist_name %>&quot;>
<input type=&quot;hidden&quot; name=&quot;dist_number&quot; value=&quot;<% dist_number %>&quot;>
 
Almost... you are missing your response.write (= is the shorthand)...
<input type=&quot;hidden&quot; name=&quot;dist&quot; value=&quot;<%= dist_name %>&quot;>
<input type=&quot;hidden&quot; name=&quot;dist_number&quot; value=&quot;<%= dist_number %>&quot;>
 
My brain did not come to work with me today.

could you spell out the line with the correct syntax please?


<input type=&quot;hidden&quot; name=&quot;dist&quot; value=&quot;<% dist_name %>&quot;>

Thanks,
Rick


(my head hurts)
 
<input type=&quot;hidden&quot; name=&quot;dist&quot; value=&quot;<%=dist_name %>&quot;>

All you need to do is add an &quot;=&quot; sign (without the quotes) in front of your variable name inside the <% %> tags.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top