OK Experts,

I have a combo-box, and a text-box. I also have two seperate recordsets.I want to populate the text box with a value from TBALE 2 which is filtered through the combo-box. i.e. Choose a value in the combo-box, and the text box auto-fills with the appropriate TABLE 2 value.

=Populates combo-box

=Will populate text-box
=with User_ID based on
=MSC_ID chosen in combo-box
MSCManager_ID (PK)
User_ID (Value that goes in text box)

*There are some other quirks involved. 1) I am already using an "OnChange" event with JS on the combo-box, 2) There will be multiple records on the page at the same time. End result is a page that allows me to update mulitple records, loop through them and update at the same time.

Who is Participating?
NetminderConnect With a Mentor Commented:
PAQed with points refunded (500)

Site Admin
So the combo box is a list of values from table 1 and when an option is selected, you want to check that value against values from table 2 and then populate the text box accordingly?

Also, could you please post the code you have so far so I can get a better idea of the layout of your page/script
you can have more than one JS function run in the onchange event handler.
<select id="ex" onchange="dosomething(); nowdothis(param, param2); thisisnext(); fourthfunction(param);">
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

NickJPhillipsAuthor Commented:
This is the complete code for the entire page. Right now the page uses a recordset to populate the table. There are two additional recordsets (mentioned in my first post) that will be used to update the two values in the first table. The JAVASCRIPT is used in the onchange of the of select box to place the ID number of each record into a hidden field. When the page is updated each variable is looped through and updated as needed.

What I want to do is also add to the onchange event a new function that can use the value in the select box to grab an ID from the other recordset to update a text box.



<!--#include virtual="/Connections/strCustoms.asp" -->
<!--#include virtual="/Includes/incCommon.asp" -->
<!--#include virtual="/Includes/incSecurity_2_Manager.asp" -->

Dim intUser
intUser = ""

If Request("Submit") <> "" Then
      intRecIDs = Replace(Request("hidRecIDs"), "*", "")  ' remove all the asterisks, to create a list like this: 2, 5, 8, 9 etc.
      arrRecIDs = Split(intRecIDs, ", ")                        ' Create an array, wich will contain just the IDs of the records we need to update
      For i = 0 to Ubound(arrRecIDs)                              ' Loop trough the array
            intNum  = Replace(Request("selectMSC" & arrRecIDs(i)), "'", "''")
            set commUpdate = Server.CreateObject("ADODB.Command")
            commUpdate.ActiveConnection = MM_strCustoms_STRING
            commUpdate.CommandText = "UPDATE tbl_Stamp  SET MSC_ID = " & intNum & ", User_ID = " &intUser & "  WHERE Stamp_ID = " & arrRecIDs(i)
            commUpdate.CommandType = 1
            commUpdate.CommandTimeout = 0
            commUpdate.Prepared = true
      strMessage = i & " Record(s) Updated"
      Response.Redirect("admin_stamp_msc.asp?Message=" & strMessage)
End If


Dim rsStampList
Dim rsStampList_numRows

Set rsStampList = Server.CreateObject("ADODB.Recordset")
rsStampList.ActiveConnection = MM_strCustoms_STRING
rsStampList.Source = "SELECT tbl_Stamp.Stamp_ID, tbl_Stamp.StampNumber, tbl_Stamp.User_ID, tbl_Stamp.MSC_ID, tbl_MSC.MSC, tbl_FOB.FOB, tbl_Rank.Rank, tbl_User.UserLName, tbl_User.UserFName, tbl_User.UserPhone, tbl_User.UserSIPR  FROM tbl_FOB RIGHT JOIN (tbl_Rank RIGHT JOIN (tbl_User RIGHT JOIN (tbl_MSC RIGHT JOIN tbl_Stamp ON tbl_MSC.MSC_ID = tbl_Stamp.MSC_ID) ON tbl_User.User_ID = tbl_Stamp.User_ID) ON tbl_Rank.Rank_ID = tbl_User.UserRank_ID) ON tbl_FOB.FOB_ID = tbl_User.FOB_ID  ORDER BY tbl_Stamp.StampNumber;  "
rsStampList.CursorType = 0
rsStampList.CursorLocation = 2
rsStampList.LockType = 1

rsStampList_numRows = 0

Dim rsMSC
Dim rsMSC_numRows

Set rsMSC = Server.CreateObject("ADODB.Recordset")
rsMSC.ActiveConnection = MM_strCustoms_STRING
rsMSC.Source = "SELECT tbl_MSC.MSC_ID, tbl_MSC.MSC, tbl_MSC.MSC_ID, tbl_MSCManager.User_ID AS MSCManager_ID  FROM tbl_MSC INNER JOIN tbl_MSCManager ON tbl_MSC.MSC_ID = tbl_MSCManager.MSC_ID  ORDER By tbl_MSC.MSC"
rsMSC.CursorType = 0
rsMSC.CursorLocation = 2
rsMSC.LockType = 1

rsMSC_numRows = 0

Dim Repeat1__numRows
Dim Repeat1__index

Repeat1__numRows = -1
Repeat1__index = 0
rsStampList_numRows = rsStampList_numRows + Repeat1__numRows

<!--#include virtual="/Includes/incHead.asp" -->

<script language="JavaScript">
//  When the value in a textfield is changed, notice the onChange="RecUpdate('<%= intRecID %>')"
//  on each of the textfields,  the value of the Record ID associated with that field
//  is passed to the RecUpdate function. First the value is surounded with 2 asterisks e.g. *6*
//  This is so that *1* can be distinguished from *10*, *11* etc.

function RecUpdate(RecID)

var ThisID = "*" + (RecID) + "*"
if (document.frmStamp.hidRecIDs.value == ""){      // If the hidden field is empty
document.frmStamp.hidRecIDs.value = (ThisID)      // Store the value in the hidden field (hidRecIDs) as it is.
if (document.frmStamp.hidRecIDs.value != ""){  // If the hidden field isn't empty
var str = document.frmStamp.hidRecIDs.value;      // Store the contents of the hidden field in the variable str
var pos = str.indexOf(ThisID);                        // Search str to see if this RecID is allready in it.
if (pos == -1) {                                          // If the position returned is -1 it isn't allredy in there,  
document.frmStamp.hidRecIDs.value = document.frmStamp.hidRecIDs.value + ", " + (ThisID)  
}                                                                   // so add ", " and this ID to what is already in hidRecIDs
}                                                                  // to create a list like this *2*, *5*, *8* etc.      


<body onmousemove="closesubnav(event);">

<!--#include file="Includes/incMasthead.asp" -->

<div id="pagecell1">
  <div id="content">
    <div class="feature">
      <h3>Assign Stamps To MSC </h3>

      <p> Use this page to assign each stamp in the inventory to an MSC. </p>

     <% =Request.QueryString("Message")%><br>

      <form action="" method="post" name="frmStamp">
        <% intRecID = (rsStampList.Fields.Item("Stamp_ID").Value) %>
        <table width="99%" border="0">
                      <td width="7%"><div align="center"><strong>STAMP</strong></div></td>
                      <td width="19%"><div align="left"><strong>OWNING MSC </strong></div></td>
                      <td width="9%"><div align="center"><strong>LOCATION</strong></div></td>
                      <td width="65%"><div align="center"><strong>CUSTODIAN/CONTACT</strong></div></td>
                      <td colspan="4"><hr></td>
While ((Repeat1__numRows <> 0) AND (NOT rsStampList.EOF))

<% intRecID =(rsStampList.Fields.Item("Stamp_ID").Value) ' Store the current RecordID in a variable %>
                        <td height="24"><span class="style4">
                                <input name="hidRecID<%= intRecID %>" type="hidden" value="<%= intRecID %>" size="5">
                        <td><span class="style4">
                                <label for="select"></label>
                          <select name="selectMSC<%= intRecID %>" id="select" onChange="RecUpdate('<%= intRecID %>')">
                            <option value="" <%If (Not isNull((rsStampList.Fields.Item("MSC_ID").Value))) Then If ("" = CStr((rsStampList.Fields.Item("MSC_ID").Value))) Then Response.Write("selected=""selected""") : Response.Write("")%>>::Select MSC::</option>
While (NOT rsMSC.EOF)
                <option value="<%=(rsMSC.Fields.Item("MSC_ID").Value)%>" <%If (Not isNull((rsStampList.Fields.Item("MSC_ID").Value))) Then If (CStr(rsMSC.Fields.Item("MSC_ID").Value) = CStr((rsStampList.Fields.Item("MSC_ID").Value))) Then Response.Write("selected=""selected""") : Response.Write("")%> ><%=(rsMSC.Fields.Item("MSC").Value)%></option>
If (rsMSC.CursorType > 0) Then
End If
            <td nowrap><span class="style4"><%=(rsStampList.Fields.Item("FOB").Value)%></span></td>
            <td nowrap><span class="style4"><%=(rsStampList.Fields.Item("Rank").Value)%>&nbsp;<%=(rsStampList.Fields.Item("UserFName").Value)%>&nbsp;<%=(rsStampList.Fields.Item("UserLName").Value)%>&nbsp;
                  <%If (rsStampList.Fields.Item("UserPhone").Value) <>"" Then%>
                  <%End If%>
                  <%If (rsStampList.Fields.Item("UserSIPR").Value) <>"" Then%>
                  <%End If%>
        <input name="hidRecIDs" type="text" size="40">
        <input name="User_ID" type="hidden" id="User_ID">
        <input type="submit" name="Submit" value="Update">

<!--end pagecell1-->
<br />

<!--#include file="Includes/incClosingScripts.asp" -->

Set rsStampList = Nothing
Set rsMSC = Nothing
NickJPhillipsAuthor Commented:
OH, in the above the third recordset isnt in there yet. This will be a simple recordset that lists a user_id for each MSC as such:

MSC_ID (this will be selected from the select box)
User_ID (this is the value that needs to go into the box)

The field that gets updated is actually the field: tbl_Stamp.User_ID from the first recordset.
NickJPhillipsAuthor Commented:
OK, Folks, I already figured it out!!! I just added another recordset INSIDE my loop and assigned a variable to it. This allowed me to get what I wanted. It might not be terribly efficient as it means another call to the database, but there is limited people using it so it shouldnt be too bad.

We can cancel the question!!!! Thank you anyways.
NickJPhillipsAuthor Commented:
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.