Posted on 2006-06-12
Last Modified: 2008-02-01
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.

Question by:NickJPhillips

Expert Comment

ID: 16887668
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

Expert Comment

ID: 16888105
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);">

Author Comment

ID: 16900080
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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.


Author Comment

ID: 16900098
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.

Author Comment

ID: 16900224
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.

Author Comment

ID: 16940538

Accepted Solution

Netminder earned 0 total points
ID: 17169706
PAQed with points refunded (500)

Site Admin

Featured Post

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Select2 jquery help 9 89
Error in query expression 3 43
Select record with the most recent date 14 56
Query still returning duplicates 5 30
I recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question