Solved

OnChange

Posted on 2006-06-12
8
713 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.

0
Comment
Question by:NickJPhillips
8 Comments
 
LVL 6

Expert Comment

by:inviser
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
0
 
LVL 3

Expert Comment

by:VAScott
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);">
...
</select>
0
 

Author Comment

by:NickJPhillips
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.




////////////////////////////////////////////////
/////////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
%>
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Author Comment

by:NickJPhillips
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:

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.
0
 

Author Comment

by:NickJPhillips
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.
0
 

Author Comment

by:NickJPhillips
ID: 16940538
Cancel
0
 
LVL 5

Accepted Solution

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

Netminder
Site Admin
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
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…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

743 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now