I am trying to accomplish the following using an asp page with vbscript. I have a basic web page with a basic input box called EmpNumber. This is where the employee number is entered by the user.
I have a Lookup button next to it. When clicked, I want it to take the EmpNumber that was input on a form, not a popup, and lookup the employee name that correlates with the EmpNumber that was input and display it on the form, not as a popup.
I have the database connection working okay, just cannot get the employee name to update. I tried using the form.empname.value but can't quite get it right.
Any help is appreciated. Thank you!
Code:
<%@ Language=VBScript %>
<%Response.Buffer="True"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>Benefit Record</title>
<link href="css/Benefits.css" rel="stylesheet" type="text/css">
<%
Sub butLookUp_onClick()
frmBenRec2011.strFullName.Value = LookUp( frmBenRec2011.strEmpNumber.value )
End Sub
Sub Lookup( strENum )
Dim strConn, objConn, objRec, strQuote, strSQL, strFirstName, strLastName
strConn = "DSN=dbsrv;" & _
"UID=websrvr;" & _
"PWD=password"
Set objConn=Server.CreateObject ("ADODB.Connection")
Set objRec=Server.CreateObject ("ADODB.Recordset")
strQuote=chr(39)
objConn.Open strConn
strSQL="select * from dny.employees WHERE emp_number = " & strquote & strENum & strQuote
objRec.Open strSQL, objConn, adOpenForwardOnly
strFirstName = objRec("first_name")
strLastName = objRec("last_name")
strFullName = strFirstName + strLastName
objRec.Close
objConn.Close
Set objRec = Nothing
Set objConn = Nothing
End Sub
%>
</head>
<body>
<form method="POST" action="" name="frmBenRec2011" language="JavaScript">
<table class="" id="tblHidden">
<tr>
<td>Employee Number</td>
<td></td>
<td><input class="Input" name="strEmpNumber" size="3"></td>
<td></td>
<td><input type=button value="Lookup" id="butLookUp"></td>
</tr>
<tr>
<td><input Name="entry_ts" Value='<%=Date%> <%=Time%>'></td>
<td><%=strFirstname%></td>
<td><%=strLastname%></td>
<td><%=strFullName%></td>
<td>Full: <input class="Input" name="strFullName" size="35"></td>
</tr>
</table>
</form>
</body>
</html>