If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > ASP > populate text field from value selected from drop down menu

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 02-01-06, 04:30
lindentree lindentree is offline
Registered User
 
Join Date: Nov 2004
Posts: 22
populate text field from value selected from drop down menu

I have a drop down menu which is populated from a database. The database contains, amongst other info, staff name, staff no.

The drop down displays the staff names.

On selecting the staff name required I need to store the appropriate staff no in a text box.

I know I need to use the Onchange function but I don't know how to code the function.

I have searched everywhere and not found any code which works.
Any help would be gratefully rec'd
Reply With Quote
  #2 (permalink)  
Old 02-01-06, 19:58
Jelly Link Jelly Link is offline
Registered User
 
Join Date: Dec 2003
Posts: 39
u may use client side script

<script language="Javascript">
function showNo()
{
frmStaff.staffNo.value=frmStaff.staffName.value;
}
</script>
<%
dim cn, rs
set cn=server.createobject("ADODB.CONNECTION")
set rs=server.createobject("ADODB.RECORDSET")
cn.Open "Provider=SQLOLEDB.1;Data Source=servername;Initial Catalog=dbname;User ID=uid;Password=pwd;"
rs.Open "select staffNo, staffName from staff", cn, 3, 1
%>
<form name="frmStaff" method="get">
<select name="staffName" onChange="showNo();">
<%
while not rs.eof
response.write "<option value=" & rs("staffNo") & ">" & rs("staffName") & "</option>"
rs.movenext
wend
%>
</select>
<input type="text" name="staffNo" value="" enabled="false">
</form>
<%
rs.close
cn.close
set rs=nothing
set cn=nothing
%>
__________________
Link Link
Reply With Quote
  #3 (permalink)  
Old 02-01-06, 23:02
rudra rudra is offline
L O S T in Reality
 
Join Date: Nov 2005
Location: San Francisco, CA
Posts: 506
Hi,
try this.....
<script language="JavaScript" type="text/JavaScript">
function joy()
{
window.document.form2.textfield.value=window.docum ent.form1.select.value
}
</script>

write the database population_combo code here...
<select name="select" SIZE=10 SINGLE onChange="joy()">

Joydeep
Reply With Quote
  #4 (permalink)  
Old 02-02-06, 01:35
kropes2001 kropes2001 is offline
Registered User
 
Join Date: Nov 2005
Location: Honolulu HI
Posts: 118
geez guys.. a little overkill....

lindentree,
when you are populating the <OPTION>staff nanme</option>
instead, include the Staff ID Number

<OPTION value='<%=intStaffIDNumber%>'>staff nanme</option>

it would end up looking like this


Code:
<html>
<body>

<form name="frmData">

<select name="lstEmpList" SINGLE onChange="frmData.txtTextID.value=frmData.lstEmpList.value;">
<OPTION value='1'>Staff 1</option>
<OPTION value='2'>Staff 2</option>
<OPTION value='3'>Staff 3</option>
<OPTION value='4'>Staff 4</option>
<OPTION value='5'>Staff 5</option>
</select>

<input type="text" name="txtTextID">

</form>
</body>
</html>
__________________
.
.
http://www.GetMySiteOnline.com - Can you help me Get My Site Online ? (Yes. That is EXACTLY what we do.)

http://www.GetMySiteOnline.com/FightingSpam/
__________________________
caeli enarrant gloriam Dei !
Reply With Quote
  #5 (permalink)  
Old 02-03-06, 04:58
lindentree lindentree is offline
Registered User
 
Join Date: Nov 2004
Posts: 22
thanks for all the help - I really like the simplicity of the Kropes2001 solution - the only problem I still have is that I have to store both the staff name and the staff number. I am now working through the other solutions.
Reply With Quote
  #6 (permalink)  
Old 02-03-06, 05:08
kropes2001 kropes2001 is offline
Registered User
 
Join Date: Nov 2005
Location: Honolulu HI
Posts: 118
"I have to store both the staff name and the staff number"

can you clarify that a little...
i thought it was already in the database ?
__________________
.
.
http://www.GetMySiteOnline.com - Can you help me Get My Site Online ? (Yes. That is EXACTLY what we do.)

http://www.GetMySiteOnline.com/FightingSpam/
__________________________
caeli enarrant gloriam Dei !
Reply With Quote
  #7 (permalink)  
Old 02-03-06, 05:43
lindentree lindentree is offline
Registered User
 
Join Date: Nov 2004
Posts: 22
I have a staff names database which holds (amongst other things)
Staff First name
Staff Surname
Staff no.

I am using this data to populate a new database of 'staffactions'

I have now used your code in my dropdown as follows:

<select name="selName" class="maintext" id="selName" SINGLE onChange="form1.staffno.value=form1.selName.value; " >
<%
While (NOT Staffnames.EOF)
%>
<option value="<%=(Staffnames.Fields.Item("FirstName").Val ue)&" "&(Staffnames.Fields.Item("Surname").Value)%>"><%= (Staffnames.Fields.Item("FirstName").Value)&" "&(Staffnames.Fields.Item("Surname").Value)%> </option>
<%
Staffnames.MoveNext()
Wend
If (Staffnames.CursorType > 0) Then
Staffnames.MoveFirst
Else
Staffnames.Requery

End If
%>

I then have the staffno field which has an initial allocation from the staffnames database - to cover the possibility that the first person on the list is selected:

<input name="staffno" type="text" id="staffno" value="<%=(Staffnames.Fields.Item("StaffNumber").V alue)%>" size="6" />

So what I now need to do is to get the Single Onchange function to put the correct corresponding StaffNumber into the textbox

Many thanks for all your help
Reply With Quote
  #8 (permalink)  
Old 02-03-06, 05:59
kropes2001 kropes2001 is offline
Registered User
 
Join Date: Nov 2005
Location: Honolulu HI
Posts: 118
<option value="<%=(Staffnames.Fields.Item("FirstName").Val ue)&"

change that to
<option value="<%=(Staffnames.Fields.Item("StaffNumber").V alue)&"

put the number there instad of their name.
__________________
.
.
http://www.GetMySiteOnline.com - Can you help me Get My Site Online ? (Yes. That is EXACTLY what we do.)

http://www.GetMySiteOnline.com/FightingSpam/
__________________________
caeli enarrant gloriam Dei !

Last edited by kropes2001; 02-03-06 at 06:02.
Reply With Quote
  #9 (permalink)  
Old 02-03-06, 06:09
lindentree lindentree is offline
Registered User
 
Join Date: Nov 2004
Posts: 22
but I need to store all 3 values.

By amalgamating the first name and surname in the drop down (both values and labels) I am storing their names into one field but I have to store the staff number as well as I have more than one John Smith. the new database is then forming a historical record so I can't refer back to the staffnames database for additional information as this only holds current staff.

Thanks for all your help by the way. I really is appreciated!
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On