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!

Send two values from a dropdown list

Status
Not open for further replies.

shiggyshag

Programmer
Dec 14, 2001
227
GB
Hi

I have a drop down box using the code below
<%
Response.Write &quot;<select name=ID>&quot;

While Not objRS.EOF
Response.Write &quot;<option value=&quot; & objRS(&quot;ID&quot;)
Response.Write &quot;>&quot; & objRS(&quot;Initials&quot;) & &quot; &quot; & objRS(&quot;Surname&quot;) &&quot;</option>&quot;

objRS.MoveNext
Wend

Response.Write &quot;</select>&quot;
%>

What I would like to do is when I select one of these it sends the ID and the surname to the next page

Any ides

Cheers
 
You can use client script for that.
let's say your form name is frm and your select name is sel
first you put the client script code in this code is not dependent of your object names (select and hidden field) how you call the code is(check red text later):
<script>
function setSecondValue(objSelect,objHidSelect) {
i = 0
while(i<objSelect.length) {
if(objSelect.item(i).selected) {
objHidSelect.value=objSelect.item(i).innerHTML
// alert(objHidSelect.value);
}
i++;
}
}
</script>
<form name=frm id=frm>
<%
with response
.write &quot;<input type hidden name=&quot;&quot;hidsel&quot;&quot; id=&quot;&quot;hidsel&quot;&quot;>&quot;
.Write &quot;<select name=sel id=sel onChange=&quot;&quot;setSecondValue(this,eval('frm.hid' + this.name))&quot;&quot;>&quot;
While Not objRS.EOF
.Write &quot;<option value=&quot; & objRS(&quot;ID&quot;)
.Write &quot;>&quot; & objRS(&quot;Initials&quot;) & &quot; &quot; & objRS(&quot;Surname&quot;) &&quot;</option>&quot;
objRS.MoveNext
Wend
.Write &quot;</select>&quot;
end with
%>


It is important that your hidden textbox has got the same name as your select but with the letters hid before it.
In this case your form name is frm, check the red characters frm if your form has a different name you should change this.
I allso give my objects an ID and a name (both are the same).
 
I Have an idea for that though there is probably an easier way. First on your current page you would need to put both values in your value separated by a comma:
<%
Response.Write &quot;<select name=ID>&quot;

While Not objRS.EOF
Response.Write &quot;<option value=&quot; & objRS(&quot;ID&quot;) & &quot;,&quot; & objRS(&quot;Surname&quot;)
Response.Write &quot;>&quot; & objRS(&quot;Initials&quot;) & &quot; &quot; & objRS(&quot;Surname&quot;) &&quot;</option>&quot;

objRS.MoveNext
Wend

Response.Write &quot;</select>&quot;
%>

and then on the top of your next page split the two values into an array.
Arr = Split(Cstr(Request.form(&quot;ID&quot;)),&quot;,&quot;)
tempID= Trim(Arr(0))
TempSurName = Trim(Arr(1))

<body>
.
.
.
<input type=&quot;text&quot; name=&quot;ID&quot; value=&quot;<%=tempid%>&quot;>
<input type=&quot;text&quot; name=&quot;Surname&quot; value=&quot;<%=TempSurName%>&quot;>


 
Put the following code into your select tag:

Response.Write &quot;<select name=ID onChange='document.form1.submit();'>&quot;

This will submit the form as soon as the user selects something. However, since you can only pass the value selected then you will only be passing the &quot;ID&quot; to the next page. On the next page do the following:

Dim intID

intID = Request.Form(&quot;ID&quot;)

...and now you have the value that was passed.
 
Thank you all very much In the end I used Jorgandr idea in the end.

Again Thankyou
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top