|
 |
asp_databases thread: onchange event
Message #1 by "Jonathan Cocle" <jonathancocle@h...> on Wed, 21 Aug 2002 15:23:49
|
|
Greetings,
I have a form with multiple dropbox and text area... What i would like to
do is when the page load, all fields are at default so there is no infos
in them... When the user choose the client he wants the info for all the
fields are filling with the appropriate infos. I was wondering how to do
the onchange so it will reload the page with the infos.
Thanks in advance
Jonathan
Message #2 by "the Office of Brent Allen VanderMeide" <ccbbttmm@a...> on Wed, 21 Aug 2002 12:18:54 -0600
|
|
Johnathan,
I'm not completely sure if you're using JavaScript, or VBScript, but
here's what to do.
The following example will put your information in both client-side &
server-side arrays. This way if later in the page you need the same
information, you can use it there as well.
You can easily intertwine the process of creating the server-side and
client-side arrays, I'm keeping them separate for the purpose of keeping
it simple. So that everyone may understand and learn from this.
#1 - You will need to understand arrays and sub-arrays.
#2 - You will need to know how to connect to your database.
--------------------- EXAMPLE - VBScript -----------------
<%
Dim objConn, objRec
Dim arryClients(), arryClientInfo()
Dim cClient, tClients
Set objConn = Server.CreateObject("ADODB.Connection")
Set objRec = Server.CreateObject("ADODB.Recordset")
ReDim arryClients(6, 0)
' arryClients(1, x) = arryClientID
' arryClients(2, x) = arryClientName
' arryClients(3, x) = Phone Number
' arryClients(4, x) = Email Address
' arryClients(5, x) = Contact Name
' arryClients(6, x) = Location
objConn.Open "Connection String Information"
objRec.Open "SELECT ClientID, Name, Phone, _
EMail, ContactName, Location _
FROM Clients"
If NOT objRec.BOF AND NOT objRec.EOF Then
WHILE NOT objRec.EOF
ReDim Preserve arryClients(1, (UBound(arryClients, 2)+1))
arryClients(1, UBound(arryClients, 2)) = objRec("ClientID")
arryClients(2, UBound(arryClients, 2)) = objRec("Name")
arryClients(3, UBound(arryClients, 2)) = objRec("Phone")
arryClients(4, UBound(arryClients, 2)) = objRec("EMail")
arryClients(5, UBound(arryClients, 2)) = objRec("ContactName")
arryClients(6, UBound(arryClients, 2)) = objRec("Location")
objRec.MoveNext
WEND
End If
tClients = UBound(arryClients, 2)
%>
<SCRIPT LANGUAGE="VBScript">
Dim arryClients()
ReDim arryClients(6, 0)
<%
cClient = 0
WHILE cClient <= tClients
%>
ReDim Preserve arryClients(6, UBound(arryClients, 2))
arryClients(1, UBound(arryClients, 2)) = _
"<%= arryClients(1, cClient) %>"
arryClients(2, UBound(arryClients, 2)) = _
"<%= Replace(arryClients(2, cClient), """", """""") %>"
arryClients(3, UBound(arryClients, 2)) = _
"<%= Replace(arryClients(3, cClient), """", """""") %>"
arryClients(4, UBound(arryClients, 2)) = _
"<%= Replace(arryClients(4, cClient), """", """""") %>"
arryClients(5, UBound(arryClients, 2)) = _
"<%= Replace(arryClients(5, cClient), """", """""") %>"
arryClients(6, UBound(arryClients, 2)) = _
"<%= Replace(arryClients(6, cClient), """", """""") %>"
<%
cClient = cClient + 1
WEND
%>
Sub ClientChange
DIM RefNum
RefNum = _
document.all.Clients.options(document.all.Clients.selectedIndex).value)
document.all.ClientID.value = arryClients(1, RefNum)
document.all.Phone.value = arryClients(3, RefNum)
document.all.Email.value = arryClients(4, RefNum)
document.all.ContactName.value = arryClients(5, RefNum)
document.all.Location.value = arryClients(6, RefNum)
End Sub
</SCRIPT>
<SELECT NAME="Clients" ID="Clients" ONCHANGE="VBScript:ClientChange">
<%
cClient = 0
WHILE cClient <= tClients
%>
<OPTION VALUE="<%= currentClient %>">
<%= arryClients(2, currentClient) %></OPTION>
</OPTION>
<%
cClient = cClient + 1
WEND
%>
</SELECT>
<!-- THE FIELDS THAT NEED TO BE POPUPLATED UPON SELECTION -->
<INPUT TYPE="hidden" NAME="ClientID" ID="ClientID" VALUE="">
<TABLE CELLSPACING="0" CELLPADDING="0" BORDER="0">
<TR>
<TD>Contact Name</TD>
<TD> : </TD>
<TD>
<INPUT TYPE="text" NAME="ContactName" ID="ContactName" VALUE="">
</TD>
</TR>
<TR>
<TD>Location</TD>
<TD> : </TD>
<TD>
<INPUT TYPE="text" NAME="Location" ID="Location" VALUE="">
</TD>
</TR>
<TR>
<TD>Phone Number</TD>
<TD> : </TD>
<TD>
<INPUT TYPE="text" NAME="Phone" ID="Phone" VALUE="">
</TD>
</TR>
<TR>
<TD>Email Address</TD>
<TD> : </TD>
<TD>
<INPUT TYPE="text" NAME="EMail" ID="EMail" VALUE="">
</TD>
</TR>
</TABLE>
<!-- NOW INITITATE THE FIRST SELECTION -->
<!-- BY CALLING THE ClientChange FUNCTION -->
<SCRIPT LANGUAGE="VBScript">
ClientChange
</SCRIPT>
Thank You,
Brent Allen VanderMeide
Intermountain Software Solutions
Senior Web / Application Engineer
Message #3 by "Jonathan Cocle" <jonathancocle@h...> on Thu, 22 Aug 2002 14:09:38
|
|
Thanks a lot that helped me a lot :)
Jonathan
> Johnathan,
I'm not completely sure if you're using JavaScript, or VBScript, but
here's what to do.
The following example will put your information in both client-side &
server-side arrays. This way if later in the page you need the same
information, you can use it there as well.
You can easily intertwine the process of creating the server-side and
client-side arrays, I'm keeping them separate for the purpose of keeping
it simple. So that everyone may understand and learn from this.
#1 - You will need to understand arrays and sub-arrays.
#2 - You will need to know how to connect to your database.
--------------------- EXAMPLE - VBScript -----------------
<%
Dim objConn, objRec
Dim arryClients(), arryClientInfo()
Dim cClient, tClients
Set objConn = Server.CreateObject("ADODB.Connection")
Set objRec = Server.CreateObject("ADODB.Recordset")
ReDim arryClients(6, 0)
' arryClients(1, x) = arryClientID
' arryClients(2, x) = arryClientName
' arryClients(3, x) = Phone Number
' arryClients(4, x) = Email Address
' arryClients(5, x) = Contact Name
' arryClients(6, x) = Location
objConn.Open "Connection String Information"
objRec.Open "SELECT ClientID, Name, Phone, _
EMail, ContactName, Location _
FROM Clients"
If NOT objRec.BOF AND NOT objRec.EOF Then
WHILE NOT objRec.EOF
ReDim Preserve arryClients(1, (UBound(arryClients, 2)+1))
arryClients(1, UBound(arryClients, 2)) = objRec("ClientID")
arryClients(2, UBound(arryClients, 2)) = objRec("Name")
arryClients(3, UBound(arryClients, 2)) = objRec("Phone")
arryClients(4, UBound(arryClients, 2)) = objRec("EMail")
arryClients(5, UBound(arryClients, 2)) = objRec("ContactName")
arryClients(6, UBound(arryClients, 2)) = objRec("Location")
objRec.MoveNext
WEND
End If
tClients = UBound(arryClients, 2)
%>
<SCRIPT LANGUAGE="VBScript">
Dim arryClients()
ReDim arryClients(6, 0)
<%
cClient = 0
WHILE cClient <= tClients
%>
ReDim Preserve arryClients(6, UBound(arryClients, 2))
arryClients(1, UBound(arryClients, 2)) = _
"<%= arryClients(1, cClient) %>"
arryClients(2, UBound(arryClients, 2)) = _
"<%= Replace(arryClients(2, cClient), """", """""") %>"
arryClients(3, UBound(arryClients, 2)) = _
"<%= Replace(arryClients(3, cClient), """", """""") %>"
arryClients(4, UBound(arryClients, 2)) = _
"<%= Replace(arryClients(4, cClient), """", """""") %>"
arryClients(5, UBound(arryClients, 2)) = _
"<%= Replace(arryClients(5, cClient), """", """""") %>"
arryClients(6, UBound(arryClients, 2)) = _
"<%= Replace(arryClients(6, cClient), """", """""") %>"
<%
cClient = cClient + 1
WEND
%>
Sub ClientChange
DIM RefNum
RefNum = _
document.all.Clients.options(document.all.Clients.selectedIndex).value)
document.all.ClientID.value = arryClients(1, RefNum)
document.all.Phone.value = arryClients(3, RefNum)
document.all.Email.value = arryClients(4, RefNum)
document.all.ContactName.value = arryClients(5, RefNum)
document.all.Location.value = arryClients(6, RefNum)
End Sub
</SCRIPT>
<SELECT NAME="Clients" ID="Clients" ONCHANGE="VBScript:ClientChange">
<%
cClient = 0
WHILE cClient <= tClients
%>
<OPTION VALUE="<%= currentClient %>">
<%= arryClients(2, currentClient) %></OPTION>
</OPTION>
<%
cClient = cClient + 1
WEND
%>
</SELECT>
<!-- THE FIELDS THAT NEED TO BE POPUPLATED UPON SELECTION -->
<INPUT TYPE="hidden" NAME="ClientID" ID="ClientID" VALUE="">
<TABLE CELLSPACING="0" CELLPADDING="0" BORDER="0">
<TR>
<TD>Contact Name</TD>
<TD> : </TD>
<TD>
<INPUT TYPE="text" NAME="ContactName" ID="ContactName" VALUE="">
</TD>
</TR>
<TR>
<TD>Location</TD>
<TD> : </TD>
<TD>
<INPUT TYPE="text" NAME="Location" ID="Location" VALUE="">
</TD>
</TR>
<TR>
<TD>Phone Number</TD>
<TD> : </TD>
<TD>
<INPUT TYPE="text" NAME="Phone" ID="Phone" VALUE="">
</TD>
</TR>
<TR>
<TD>Email Address</TD>
<TD> : </TD>
<TD>
<INPUT TYPE="text" NAME="EMail" ID="EMail" VALUE="">
</TD>
</TR>
</TABLE>
<!-- NOW INITITATE THE FIRST SELECTION -->
<!-- BY CALLING THE ClientChange FUNCTION -->
<SCRIPT LANGUAGE="VBScript">
ClientChange
</SCRIPT>
Thank You,
Brent Allen VanderMeide
Intermountain Software Solutions
Senior Web / Application Engineer
Message #4 by "Brent VanderMeide" <ccbbttmm@a...> on Tue, 27 Aug 2002 20:11:52
|
|
Your welcome, however there was one little issue that I have found while I
review my response. Please review the following corrections in the code
excerpt
EXCERPT OF CODE
_____________________________________________________________
End If
tClients = UBound(arryClients, 2)
%>
<SCRIPT LANGUAGE="VBScript">
Dim arryClients()
ReDim arryClients(6, 0)
<%
cClient = 0
WHILE cClient <= tClients
%>
********************************************************
*********** THIS WAS WRITTEN INCORRECTLY ***************
ReDim Preserve arryClients(6, UBound(arryClients, 2))
********************************************************
************** SHOULD HAVE BEEN ************************
ReDim Preserve arryClients(6, UBound(arryClients, 2) + 1)
********************************************************
arryClients(1, UBound(arryClients, 2)) = _
"<%= arryClients(1, cClient) %>"
_____________________________________________________________
|
|
 |