OGSan
asked on
Need to pass variable in Javascript to my ASP pgm
Expert Carrzkiss helped me with a bit of ASP 3.0 code in order to get my pgm to display a dropdown box populated with employees that the User is authorized to enter payroll time for (see Q_24240327). A Javascript routine was used to capture the Empl ID associated with the selected employee. Problem now is I need to pass that value to my ASP pgm...hopefully without leaving the page.
Is this possible to do? Below is the relevant code.
Is this possible to do? Below is the relevant code.
<!-- Save the Selected Empl ID from the dropdown -->
<script type="text/javascript">
var strSelectedID;
function showSelected(val){
strSelectedID = val;
document.getElementById
('selectedResult').innerHTML = "Empl ID = "+strSelectedID;
}
</script>
.
.
.
'-- F I L L D R O P D O W N W I T H E M P L O Y E E S -->
' Open connection string to the Sick Time Entry Online database
If not IsObject(objSickOnlineConn) then
strDataPath = server.MapPath("/hr/db/public/AbsTimeEntryOnline.mdb;")
set objSickOnlineConn = Server.CreateObject("ADODB.Connection")
strConnectString = "Provider=Microsoft.Jet.OLEDB.4.0;"_
+ " Data Source= " & strDataPath & ";"_
+ " Mode=Share Deny None;"
objSickOnlineConn.ConnectionTimeout = 15
objSickOnlineConn.CommandTimeout = 10
objSickOnlineConn.Mode = 3 'adModeReadWrite
if objSickOnlineConn.state = 0 then
objSickOnlineConn.Open strConnectString
end if
end if
'***** T E S T I N G O N L Y ***** TEST ONLY!
strEmplID = "1000003"
sql = "SELECT DISTINCT [EmplID_(OPRDEFN)], [EE Name] AS EE_Name, [EmplID_(GROUP_DTL)] AS Selected_ID FROM tbl_EmplID_RowSecurity_xref WHERE (([EmplID_(OPRDEFN)])=" & strEmplID & ") Order by [EE Name];"
'***** D E B U G *****
' Response.Write(sql & "<br>")
set rsSelect = objSickOnlineConn.execute(sql)
%>
<form>
<select name="Name" style="font: 8pt verdana;" onChange='showSelected(this.value)'>
<option value="">Select Employee</option>
<%
While (NOT rsSelect.EOF)
%>
<option value="<%=(rsSelect.Fields.Item("Selected_ID").Value)%>" <%if (CStr(rsSelect.Fields.Item("EE_Name").Value) = CStr(rsSelect.Fields.Item("EE_Name").Value)) then Response.Write("SELECTED") : Response.Write("EE_Name")%>><%=(rsSelect.Fields.Item("EE_Name").Value)%></option>
<%
rsSelect.moveNext()
Wend
If (rsSelect.CursorType > 0) Then
rsSelect.MoveFirst
Else
rsSelect.Requery
End If
' added in to the bottom, and extra Blank Select, for those DEEP Select List, instead of scrolling to the top, the visitor can simply choose this to end the use of this area.
%>
</select>
</form>
<%
' Close connection, deinitialize from memory
rsSelect.close
set rsSelect = nothing
objSickOnlineConn.Close
set objSickOnlineConn = nothing
%>
<!-- Employee ID is displayed below -->
<div id='selectedResult'></div>
<!-- But how do I get it back to ASP? -->
<%
Response.Write("***** D E B U G S T A R T *****<br>")
Response.Write("strSelectedID: " & strSelectedID & "<br>")
Response.Write("***** D E B U G E N D *****<br>")
%>
ASKER
Thanks, Carrzkiss.
I need to pass the value being stored in the Javascript variable, "strSelectedID", to the ASP code so I can run a query to get employee-specific info.
I've modified your code slightly (changed some names), but have posted it below. This will work with the database from before.
Let me know if I was not clear.
I need to pass the value being stored in the Javascript variable, "strSelectedID", to the ASP code so I can run a query to get employee-specific info.
I've modified your code slightly (changed some names), but have posted it below. This will work with the database from before.
Let me know if I was not clear.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Test-a-roonie!</title>
<!-- Save the Selected Empl ID from the dropdown -->
<script type="text/javascript">
var strSelectedID;
function showSelected(val){
strSelectedID = val;
document.getElementById
('selectedID').innerHTML = "Empl ID = "+strSelectedID;
}
</script>
</head>
<%
if not IsObject(objSickOnlineConn) then
strDataPath = server.MapPath("/hr/db/public/AbsTimeEntryOnline.mdb;")
set objSickOnlineConn = Server.CreateObject("ADODB.Connection")
strConnectString = "Provider=Microsoft.Jet.OLEDB.4.0;"_
+ " Data Source= " & strDataPath & ";"_
+ " Mode=Share Deny None;"
objSickOnlineConn.ConnectionTimeout = 15
objSickOnlineConn.CommandTimeout = 10
objSickOnlineConn.Mode = 3 'adModeReadWrite
if objSickOnlineConn.state = 0 then
objSickOnlineConn.Open strConnectString
end if
end if
'***** T E S T I N G O N L Y ***** TEST ONLY!
strEmplID = "1000003"
sql = "SELECT DISTINCT [EmplID_(OPRDEFN)], [EE Name] AS EE_Name, [EmplID_(GROUP_DTL)] AS Selected_ID FROM tbl_EmplID_RowSecurity_xref WHERE (([EmplID_(OPRDEFN)])=" & strEmplID & ") Order by [EE Name];"
set rsSelect = objSickOnlineConn.execute(sql)
%>
<body>
<form>
<select name="Name" style="font: 8pt verdana;" onChange='showSelected(this.value)'>
<option value="">Select Employee</option>
<%
While (NOT rsSelect.EOF)
%>
<option value="<%=(rsSelect.Fields.Item("Selected_ID").Value)%>" <%if (CStr(rsSelect.Fields.Item("EE_Name").Value) = CStr(rsSelect.Fields.Item("EE_Name").Value)) then Response.Write("SELECTED") : Response.Write("EE_Name")%>><%=(rsSelect.Fields.Item("EE_Name").Value)%></option>
<%
rsSelect.moveNext()
Wend
If (rsSelect.CursorType > 0) Then
rsSelect.MoveFirst
Else
rsSelect.Requery
End If
%>
</select>
</form>
<%
' Close connection, deinitialize from memory
rsSelect.close
set rsSelect = nothing
objSickOnlineConn.Close
set objSickOnlineConn = nothing
%>
<div id='selectedID'></div>
<%
Response.Write("<p>***** D E B U G S T A R T *****<br>")
Response.Write("strSelectedID: " & strSelectedID & "<br>")
Response.Write("***** D E B U G E N D *****<br>")
%>
</body>
</html>
are you saying that you want to list information from each Employ?
Do you want it to show up like the demo that I made on the other one?
Each select item shows?
If so. I will look in on seeing if it can be done using the same thing.
If not, it might be something that I might be able to do with AJAX
Which is just JavaScript on Steroids.
Let me know?
Carrzkiss
Do you want it to show up like the demo that I made on the other one?
Each select item shows?
If so. I will look in on seeing if it can be done using the same thing.
If not, it might be something that I might be able to do with AJAX
Which is just JavaScript on Steroids.
Let me know?
Carrzkiss
I have it working with what I used before.
The only thing that I need to know from you now is what you
Want to be displayed?
Give me all the field Names that you want to have Displayed.
Carrzkiss
The only thing that I need to know from you now is what you
Want to be displayed?
Give me all the field Names that you want to have Displayed.
Carrzkiss
ASKER
The employee info would be all those other fields in the tbl_EmplID_RowSecurity_xre f:
EE Name, Service_Date, Business_Title, Union_Cd, YOS, NonUnion_100HrsEntitlement , U8_Sick100HrsEntitlement, U8_Sick50HrsEntitlement, U8_Sick58HrsEntitlement, and U8_WaitHours_PerIncident.
I never heard AJAX described as Javascript on steriods before - that's funny!
EE Name, Service_Date, Business_Title, Union_Cd, YOS, NonUnion_100HrsEntitlement
I never heard AJAX described as Javascript on steriods before - that's funny!
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER
Carrzkiss - Another gem of a solution! I tweaked the code in AJAX2 just to eliminate columns that were not necessary, made the results distinct, and cleaned up at the end (posted below). This is my first exposure to AJAX - it's quite handy! I've really learned a lot from you the past week. Again - thank you for sharing your skills here at EE! It is very much appreciated!
Jeff (aka OGSan)
Jeff (aka OGSan)
<%
Set dbopen = Server.CreateObject("ADODB.Connection")
dbopen.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & _
Server.MapPath ("/hr/db/public/AbsTimeEntryOnline.mdb") & ";"
dbopen.Open
sql="SELECT DISTINCT tbl_EmplID_RowSecurity_XREF.[EmplID_(GROUP_DTL)] AS EmplID_GROUP_DTL," &_
"tbl_EmplID_RowSecurity_XREF.[EE Name] AS EE_Name," &_
"tbl_EmplID_RowSecurity_XREF.SERVICE_DATE," &_
"tbl_EmplID_RowSecurity_XREF.BUSINESS_TITLE," &_
"tbl_EmplID_RowSecurity_XREF.UNION_CD," &_
"tbl_EmplID_RowSecurity_XREF.YOS," &_
"tbl_EmplID_RowSecurity_XREF.NonUnion_100HrsEntitlement," &_
"tbl_EmplID_RowSecurity_XREF.U8_Sick100HrsEntitlement," &_
"tbl_EmplID_RowSecurity_XREF.U8_Sick50HrsEntitlement," &_
"tbl_EmplID_RowSecurity_XREF.U8_Sick58HrsEntitlement," &_
"tbl_EmplID_RowSecurity_XREF.U8_WaitHours_PerIncident " &_
"FROM tbl_EmplID_RowSecurity_XREF WHERE [EmplID_(GROUP_DTL)]="
sql = sql & "" & request.querystring("q") & ""
set rs = Server.CreateObject("ADODB.recordset")
rs.Open sql, dbopen
response.write("<table>")
do until rs.EOF
for each x in rs.Fields
response.write("<tr><td><b>" & x.name & "</b></td>")
response.write("<td>" & x.value & "</td></tr>")
next
rs.MoveNext
loop
response.write("</table>")
rs.Close
set rs = nothing
dbopen.Close
set dbopen = nothing
%>
you are welcome.
I will check out your code here in a few, as I am helping another poster at the moment.
Have a good one.
Carrzkiss
I will check out your code here in a few, as I am helping another poster at the moment.
Have a good one.
Carrzkiss
I am not following you on this part?
>>>>Problem now is I need to pass that value to my ASP pgm
Let me know and I will see what I can do for you again.
Carrzkiss