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

populate text box from combo-box

Status
Not open for further replies.

gwilym40

Programmer
May 2, 2002
31
GB
Hi

I have a combo box as follows, where name is what shows and ID and email are hidden.

<p><font face=&quot;Arial&quot; size=&quot;2&quot;>Select your Name <select name = &quot;reqname&quot;>
<option value=&quot;&quot; select>Name</option>

<%Do While Not rsname.EOF
Response.Write (&quot;<OPTION value=&quot;& rsname(&quot;id&quot;) &&quot;>&quot; & rsname(&quot;email&quot;) & rsname(&quot;name&quot;) & &quot;</OPTION>&quot;)
rsname.MoveNext
Loop
rsname.Close
set rsname= Nothing %>
</select>
</font>

after the update of this combo-box I'd like to populate a text-box, named reqemail with the email address, taken from the value of the rsname(&quot;email&quot;) field from the combo-box

how can i do this please?

thanks in anticipation!!!
kim
 
>> after the update of this combo-box

You mean when the user selects one in the browser?

-pete
 
yeah when a user selects a name in the browser
 
I hope this will solve your problem

<head>
<script language=&quot;javascript&quot; >
//Used to pass the value selected from the combo box to the same page
function funcgo()
{
x=document.txtbox.reqname.value
top.location=&quot;testcmb.asp?txt=&quot; + x
}
</script>
</head>


<body>
<p><form name=&quot;txtbox&quot; action=&quot;testcmb.asp?txt=<%=request.Form(&quot;reqname&quot;)%>&quot; method=post>
<%Do While Not rsname.EOF
if request.QueryString(&quot;txt&quot;)=rsname(&quot;id&quot;) then%>
<input type=text name=&quot;text1&quot; value=&quot;<%=rsname(&quot;email&quot;)%>&quot; ID=&quot;Text1&quot;>
<%end if
rsname.movenext
loop
rsname.movefirst%>

<font face=&quot;Arial&quot; size=&quot;2&quot;>Select your Name <select name = &quot;reqname&quot; onchange=&quot;funcgo()&quot;>
<option value=&quot;&quot; >Name</option>
<%Do While Not rsname.EOF
if request.QueryString(&quot;txt&quot;)=rsname(&quot;id&quot;) then
Response.Write (&quot;<OPTION value=&quot;& rsname(&quot;id&quot;) &&quot; selected>&quot; & rsname(&quot;email&quot;) &&quot; > &quot;& rsname(&quot;name&quot;) & &quot;</OPTION>&quot;)
else
Response.Write (&quot;<OPTION value=&quot;& rsname(&quot;id&quot;) &&quot; >&quot; & rsname(&quot;email&quot;) &&quot; > &quot;& rsname(&quot;name&quot;) & &quot;</OPTION>&quot;)
end if
rsname.MoveNext
Loop
rsname.Close
set rsname= Nothing %>
</select>
</font>
</form>

</body>
 
Hmm, why not just place a delimiter between the email and name in the option, than pull out the first part of the text and place it in the hidden field?

in your javascript section(pretend frmYourForm is your form name):
Code:
function setEmail(){
   var selElem = frmYourForm.reqname;
   var tOptText = selElem.options[selElem.selectedIndex].text;
   tOptText = tOptText.substring(0,tOptText.IndexOf(&quot; &quot;)-1;
   frmYourForm.hdnEmail.value = tOptText;
}

in your select section:
Code:
<select name=&quot;reqname&quot; onClick=&quot;setEmail();&quot;>
<option value=&quot;&quot; select>Name</option>
<%Do While Not rsname.EOF
Response.Write (&quot;<OPTION value='&quot;& rsname(&quot;id&quot;) &&quot;'>&quot; & rsname(&quot;email&quot;) & &quot; &quot; & rsname(&quot;name&quot;) & &quot;</OPTION>&quot;)        
rsname.MoveNext
Loop
rsname.Close
set rsname= Nothing %>
<input type=&quot;hidden&quot; name=&quot;hdnEmail&quot;>
</select>
</font>

Basically I added a space between your email and name in the option and then, since the email shouldn't have a space in it, I pulled out everything up to ther space and placed it in the hidden field. This was written on the fly so it may have be a little rough, but the logic should be sound.

-Tarwn --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- ---
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top