We help IT Professionals succeed at work.

OnChange

NickJPhillips
on
770 Views
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
=====================
TBL_MSC
____________________
MSC_ID (PK)
MSC


========================
=Will populate text-box
=with User_ID based on
=MSC_ID chosen in combo-box
========================
TBL_MSCManager
_______________________
MSCManager_ID (PK)
MSC_ID (FK from TBL_MSC)
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.

Comment
Watch Question

Commented:
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

Commented:
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);">
...
</select>

Author

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.




////////////////////////////////////////////////
/////////CODE
///////////////////////////////////////////////

<%@LANGUAGE="VBSCRIPT"%>

<!--#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
            commUpdate.Execute()
      Next
      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.Open()

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.Open()

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.      
}
//-->
</script>


</head>

<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">
              <tr>
                      <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>
              </tr>
              <tr>
                      <td colspan="4"><hr></td>
              </tr>
       
<%
While ((Repeat1__numRows <> 0) AND (NOT rsStampList.EOF))
%>
                <tr>

<% 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">
                                <%=(rsStampList.Fields.Item("StampNumber").Value)%></span></td>
                        <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>
                <%
  rsMSC.MoveNext()
Wend
If (rsMSC.CursorType > 0) Then
  rsMSC.MoveFirst
Else
  rsMSC.Requery
End If
%>
              </select>
            </span></td>
            <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%>
                  <strong>PHONE:</strong><%=(rsStampList.Fields.Item("UserPhone").Value)%>
                  <%End If%>
                  <%If (rsStampList.Fields.Item("UserSIPR").Value) <>"" Then%>
                  <strong>&nbsp;E-MAIL:</strong><%=(rsStampList.Fields.Item("UserSIPR").Value)%></span>
                  <%End If%>
                  </td>
                </tr>
         
          <%
  Repeat1__index=Repeat1__index+1
  Repeat1__numRows=Repeat1__numRows-1
  rsStampList.MoveNext()
Wend
%>
      </table>
        <input name="hidRecIDs" type="text" size="40">
        <input name="User_ID" type="hidden" id="User_ID">
        <input type="submit" name="Submit" value="Update">
        </form>
      <p>&nbsp;</p>
    </div>
   
      

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

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

</body>
</html>
<%
rsStampList.Close()
Set rsStampList = Nothing
%>
<%
rsMSC.Close()
Set rsMSC = Nothing
%>

Author

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:

TABLE:
MSCManager_ID
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

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.

Author

Commented:
Cancel
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.