Avatar of OGSan
OGSan
Flag for United States of America

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.
<!-- 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&nbsp;&nbsp;&nbsp;S T A R T *****<br>")  
Response.Write("strSelectedID: " & strSelectedID & "<br>")
Response.Write("***** D E B U G&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;E N D   *****<br>") 
%>

Open in new window

ASP

Avatar of undefined
Last Comment
Wayne Barron

8/22/2022 - Mon