473,408 Members | 1,683 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

Client side and server side scripting problem

Hiya
I have a problem with using some client side and server side scripting
together in an ASP. I'm using VBScript.

What I'm trying to achieve is this -

- Page loads up and some server side vbscript reads the database and
populates a listbox on the page with the first field from each record
in the recordset. This works fine.
- User selects an option on the listbox and, using the OnChange, I
call a client side vbscript function. This function needs to populate
the text fields on the page with the rest of the fields from the
relevant record in the recordset in the server side script that was
done when the page loaded up.

I realise that mixing server side and client side isn't possible but
I'm looking for a way around this. What I can do is create an array in
the server side code from the recordset and then pass this array into
the function. I'm having trouble getting this to work though. The
problem is that it doesn't seem to want to populate the text fields.
It goes into the function alright because if I put an alert in there
it appears when I select something from the list box.

Here's some snippets from my code

The server side script

<%'Set up and open the connection to the database
dim conn, rs, StructureArray(10,10)
set conn=Server.CreateObject("ADODB.Connection")
conn.provider="Microsoft.Jet.OLEDB.4.0"
conn.open(server.mappath("structures.mdb"))

set rs = Server.CreateObject ("ADODB.recordset")
rs.Open "SELECT * FROM RunStructureValues WHERE WorkspaceID = '12',
conn

for intRow = 1 to StructureNameRS.RecordCount
StructureArray(intRow,1) = StructureNameRS.Fields("RunNumber")
StructureArray(intRow,2) = StructureNameRS.Fields("MPFLoc")
StructureArray(intRow,3) = StructureNameRS.Fields("MPFExt")
intRow = intRow + 1
next
%>

The client side script

<script language="VBScript">
function UpdateFields(StructureArray)
dim index
index = form1.RunStructureName.selectedIndex
form1.RunNumber.value = StructureArray(index,1)
form1.MPFLoc.value = StructureArray(index,2)
form1.MPFExt.value = StructureArray(index,3)
end function
</script>

The form

<form method="post" action="action.asp" target="_self" name="form1">
<table>
<tr>
<td class="SubHeader">Run Structure</td>
<td>
<SELECT name="RunStructureName"
onchange="UpdateFields(<%=StructureArray%>)">
<%
do until StructureNameRS.EOF%>
<OPTION><%=StructureNameRS.Fields("RunStructureNam e")%></OPTION>
<%
StructureNameRS.MoveNext
loop
%>
</SELECT>
</td>
</tr>
<tr>
<td class="SubHeader">Run Number</td>
<td><input type="text" name="RunNumber" value=""></td>
</tr>
<tr>
<td class="SubHeader">Model Point File Location</td>
<td><input type="text" name="MPFLoc" value=""></td>
</tr>
<tr>
<td class="SubHeader">Model Point File Extension</td>
<td><input type="text" name="MPFExt" value=""></td>
</tr> </table>
</form>
Any advice would be greatly appreciated as my deadline is looming and
this is the one thing I'm having trouble with! If there is a better
way to do this sort of thing then please let me know also!

Thanks.
Kathryn.
Jul 19 '05 #1
9 4305
"Kathryn" <an******@hotmail.com> wrote in message
news:42************************@posting.google.com ...
Hiya
I have a problem with using some client side and server side scripting
together in an ASP. I'm using VBScript.

What I'm trying to achieve is this -

- Page loads up and some server side vbscript reads the database and
populates a listbox on the page with the first field from each record
in the recordset. This works fine.
- User selects an option on the listbox and, using the OnChange, I
call a client side vbscript function. This function needs to populate
the text fields on the page with the rest of the fields from the
relevant record in the recordset in the server side script that was
done when the page loaded up.

I realise that mixing server side and client side isn't possible but
I'm looking for a way around this. What I can do is create an array in
the server side code from the recordset and then pass this array into
the function. I'm having trouble getting this to work though. The
problem is that it doesn't seem to want to populate the text fields.
It goes into the function alright because if I put an alert in there
it appears when I select something from the list box.

Here's some snippets from my code

The server side script

<%'Set up and open the connection to the database
dim conn, rs, StructureArray(10,10)
set conn=Server.CreateObject("ADODB.Connection")
conn.provider="Microsoft.Jet.OLEDB.4.0"
conn.open(server.mappath("structures.mdb"))

set rs = Server.CreateObject ("ADODB.recordset")
rs.Open "SELECT * FROM RunStructureValues WHERE WorkspaceID = '12',
conn

for intRow = 1 to StructureNameRS.RecordCount
StructureArray(intRow,1) = StructureNameRS.Fields("RunNumber")
StructureArray(intRow,2) = StructureNameRS.Fields("MPFLoc")
StructureArray(intRow,3) = StructureNameRS.Fields("MPFExt")
intRow = intRow + 1
next
%>

The client side script

<script language="VBScript">
function UpdateFields(StructureArray)
dim index
index = form1.RunStructureName.selectedIndex
form1.RunNumber.value = StructureArray(index,1)
form1.MPFLoc.value = StructureArray(index,2)
form1.MPFExt.value = StructureArray(index,3)
end function
</script>

The form

<form method="post" action="action.asp" target="_self" name="form1">
<table>
<tr>
<td class="SubHeader">Run Structure</td>
<td>
<SELECT name="RunStructureName"
onchange="UpdateFields(<%=StructureArray%>)">
<%
do until StructureNameRS.EOF%>
<OPTION><%=StructureNameRS.Fields("RunStructureNam e")%></OPTION>
<%
StructureNameRS.MoveNext
loop
%>
</SELECT>
</td>
</tr>
<tr>
<td class="SubHeader">Run Number</td>
<td><input type="text" name="RunNumber" value=""></td>
</tr>
<tr>
<td class="SubHeader">Model Point File Location</td>
<td><input type="text" name="MPFLoc" value=""></td>
</tr>
<tr>
<td class="SubHeader">Model Point File Extension</td>
<td><input type="text" name="MPFExt" value=""></td>
</tr> </table>
</form>
Any advice would be greatly appreciated as my deadline is looming and
this is the one thing I'm having trouble with! If there is a better
way to do this sort of thing then please let me know also!


When building the array, you need to have the server script use
Response.Write to write out the client script that will build it. In your
snippet you are only establishing the array on the server side. Something
like:

Response.Write "<script>" & vbcrlf
for intRow = 1 to StructureNameRS.RecordCount
Response.Write "StructureArray(intRow,1) = " &
StructureNameRS.Fields("RunNumber") & vbcrlf
etc ...

--
Tom Kaminski IIS MVP
http://www.iistoolshed.com/ - tools, scripts, and utilities for running IIS
http://mvp.support.microsoft.com/
http://www.microsoft.com/windowsserv...y/centers/iis/

Jul 19 '05 #2
Hello Kathryn,

You are correct: you can't mix server side and client side, but you're
heading in more or less the right direction. Your client-side script has no
idea what StructureArray is, so what you need to do is write the array to
the client, and access it from there. Something like (borrowing your own
code...hand me that pencil, won't you? Thanks...):

<%
for intRow = 1 to StructureNameRS.RecordCount
StructureArray(intRow,1) = StructureNameRS.Fields("RunNumber")
StructureArray(intRow,2) = StructureNameRS.Fields("MPFLoc")
StructureArray(intRow,3) = StructureNameRS.Fields("MPFExt")
intRow = intRow + 1
next
'--- so now you've got this server side array
'--- another, possibly easier way, though you have to make your SELECT
explicit;
'--- for a variety of reasons, you shouldn't use SELECT * anyway
'--- because the array is actually going to end up on the client side, this
step might or might not be necessary,
'--- but I'd do it because I want to know my array bounds in advance.
Looping an array is faster
'--- than looping a recordset, too.
StructureArray = StructureNameRS.GetRows()
Dim rCounter, cCounter
'--- now the client side magic
With Response
.Write "<" & "script language=""VBScript"" type=""text/vbscript"">" &
vbCrLf
.Write " Dim ClientSideArray" & vbCrLf
.Write " Redim ClientSideArray(" & UBound(StructureArray) & "," &
UBound(StructureArray, 2) & ")" & vbCrLf
For rCounter = 0 to Ubound(StructureArray, 2)
For cCounter = 0 to Ubound(StructureArray)
.Write " ClientSideArray(" & rCounter & "," & cCounter & ")
= """ & StructureArray(rCounter, cCounter) & """" & vbCrLf
Next
Next
.Write "<" & "/script>" & vbCrLf
End With
'--- now you've got a client side array you can manipulate with client-side
script.
'--- the array needs to live outside a procedure so it's available to all
scripts on the page
%>

If you've got a lot of items, that client-side code is going to get huge in
a hurry and may take a while to download to the browser. However, I do
something similar with two Listboxes, one with vehicle makes and one with
vehicle models, the two linked together to popuplate the model based on the
make...that's about 500 lines, plus a lot of other code (one page is almost
2500 lines long when all the server-side stuff is done...employee lists,
zipcode lists, city lists...) and it loads without any appreciable lag time.

Hope this helps,

Wm

--
William Morris
Product Development, Seritas LLC

"Kathryn" <an******@hotmail.com> wrote in message
news:42************************@posting.google.com ...
Hiya
I have a problem with using some client side and server side scripting
together in an ASP. I'm using VBScript.

What I'm trying to achieve is this -

- Page loads up and some server side vbscript reads the database and
populates a listbox on the page with the first field from each record
in the recordset. This works fine.
- User selects an option on the listbox and, using the OnChange, I
call a client side vbscript function. This function needs to populate
the text fields on the page with the rest of the fields from the
relevant record in the recordset in the server side script that was
done when the page loaded up.

I realise that mixing server side and client side isn't possible but
I'm looking for a way around this. What I can do is create an array in
the server side code from the recordset and then pass this array into
the function. I'm having trouble getting this to work though. The
problem is that it doesn't seem to want to populate the text fields.
It goes into the function alright because if I put an alert in there
it appears when I select something from the list box.

Here's some snippets from my code

The server side script

<%'Set up and open the connection to the database
dim conn, rs, StructureArray(10,10)
set conn=Server.CreateObject("ADODB.Connection")
conn.provider="Microsoft.Jet.OLEDB.4.0"
conn.open(server.mappath("structures.mdb"))

set rs = Server.CreateObject ("ADODB.recordset")
rs.Open "SELECT * FROM RunStructureValues WHERE WorkspaceID = '12',
conn

for intRow = 1 to StructureNameRS.RecordCount
StructureArray(intRow,1) = StructureNameRS.Fields("RunNumber")
StructureArray(intRow,2) = StructureNameRS.Fields("MPFLoc")
StructureArray(intRow,3) = StructureNameRS.Fields("MPFExt")
intRow = intRow + 1
next
%>

The client side script

<script language="VBScript">
function UpdateFields(StructureArray)
dim index
index = form1.RunStructureName.selectedIndex
form1.RunNumber.value = StructureArray(index,1)
form1.MPFLoc.value = StructureArray(index,2)
form1.MPFExt.value = StructureArray(index,3)
end function
</script>

The form

<form method="post" action="action.asp" target="_self" name="form1">
<table>
<tr>
<td class="SubHeader">Run Structure</td>
<td>
<SELECT name="RunStructureName"
onchange="UpdateFields(<%=StructureArray%>)">
<%
do until StructureNameRS.EOF%>
<OPTION><%=StructureNameRS.Fields("RunStructureNam e")%></OPTION>
<%
StructureNameRS.MoveNext
loop
%>
</SELECT>
</td>
</tr>
<tr>
<td class="SubHeader">Run Number</td>
<td><input type="text" name="RunNumber" value=""></td>
</tr>
<tr>
<td class="SubHeader">Model Point File Location</td>
<td><input type="text" name="MPFLoc" value=""></td>
</tr>
<tr>
<td class="SubHeader">Model Point File Extension</td>
<td><input type="text" name="MPFExt" value=""></td>
</tr> </table>
</form>
Any advice would be greatly appreciated as my deadline is looming and
this is the one thing I'm having trouble with! If there is a better
way to do this sort of thing then please let me know also!

Thanks.
Kathryn.

Jul 19 '05 #3
KP


Hi William
Thank you so much for taking the time out to answer my question so
thoroughly.

I've used your suggestion and its working a treat. I now just have a
problem with my array so I now just need to mess about with it a bit to
get it right. I hate multi-dimensional arrays but in this case it is
very necessary :-)

I may be back if I can't figure it out!

Thanks again.
Kathryn.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 19 '05 #4
KP

Thanks Tom!
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 19 '05 #5
I've had lots of occasion to work with multidimensional arrays since joining
the company I'm with. I hate working with recordsets, especially SHAPED
recordsets, preferring instead to get the recordset into an array and
closing it as soon as possible. It's not uncommon to find references like:

response.write employeeArray(1, 2)(3, 4)

where an element of a multidimensional array ~contains~ a multidimensional
array. Of course, javascript doesn't support them so then you have to work
with arrays of arrays, as in

MakeArray[0] = "Ford"
MakeArray[0][0] = "Escort"
MakeArray[0][1] = "Fairland"
MakeArray[0][2] = "Maverick" // have I given away my age yet?

and so on.

"KP" <an*******@devdex.com> wrote in message
news:#V**************@TK2MSFTNGP12.phx.gbl...


Hi William
Thank you so much for taking the time out to answer my question so
thoroughly.

I've used your suggestion and its working a treat. I now just have a
problem with my array so I now just need to mess about with it a bit to
get it right. I hate multi-dimensional arrays but in this case it is
very necessary :-)

I may be back if I can't figure it out!

Thanks again.
Kathryn.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Jul 19 '05 #6
Should item [0][1] be "Fairlane?" I especially like the Talladega edition.
I wonder how many still exist. :]

Ray at work
"WIlliam Morris" <se**************@hotmail.com> wrote in message
news:bm************@ID-205671.news.uni-berlin.de...

MakeArray[0] = "Ford"
MakeArray[0][0] = "Escort"
MakeArray[0][1] = "Fairland"
MakeArray[0][2] = "Maverick" // have I given away my age yet?

and so on.

Jul 19 '05 #7
Erk. Fairlane...you're right! There are a couple in my town in mint
condition...one periodically uses our parking lot at breakfast time (we
share our building with an Italian restaurant).

"Ray at <%=sLocation%>" <myfirstname at lane34 dot com> wrote in message
news:OU**************@TK2MSFTNGP09.phx.gbl...
Should item [0][1] be "Fairlane?" I especially like the Talladega edition. I wonder how many still exist. :]

Ray at work
"WIlliam Morris" <se**************@hotmail.com> wrote in message
news:bm************@ID-205671.news.uni-berlin.de...

MakeArray[0] = "Ford"
MakeArray[0][0] = "Escort"
MakeArray[0][1] = "Fairland"
MakeArray[0][2] = "Maverick" // have I given away my age yet?

and so on.


Jul 19 '05 #8
KP

Thanks William, I think I've finally got my head around arrays and this
bit of my application is now working perfectly thanks to your help!

As for the cars I'm afraid I've not heard of some of the ones you are
talking about being that I'm from the UK! And being that I'm young ;-)

Kathryn.
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 19 '05 #9
Glad to hear it Kathryn. I'm not sure what the automotive equivalents are
across the Pond, so we'll just let that one go. :)

Warmest regards,

William Morris
Product Development, Seritas LLC

"KP" <an*******@devdex.com> wrote in message
news:#F**************@tk2msftngp13.phx.gbl...

Thanks William, I think I've finally got my head around arrays and this
bit of my application is now working perfectly thanks to your help!

As for the cars I'm afraid I've not heard of some of the ones you are
talking about being that I'm from the UK! And being that I'm young ;-)

Kathryn.
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Jul 19 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Matt | last post by:
I think this is the basic concept in ASP server-side development. My boss told me web application is NOT client-server application. I argued with him because browser is the client, and the server...
2
by: cedced | last post by:
Hello, is it possible to access client files in VB.NET? What? I have doing that but it isn't good (VB.NET take file on pc server and not on pc client): (thanks) Dim fichier As StreamReader ...
4
by: Bob T | last post by:
Hi All, I am trying to pass a variable from my VB asp.net script (from for example Sub Page_Load in mypage.aspx.vb) to my Client side script. I have found and looked at a very good example...
14
by: Matt | last post by:
I want to know if ASP.NET Web Forms Validation Controls are Server-Side or Client-Side form validation? Since I think each validator control can select either 1) JavaScript based error dialog or 2)...
6
by: Julius Fenata | last post by:
Dear all, I have created client-side scripting to trigger event onChange from code-behind, like this: DropDownList1.Attributes = "GenerateArticleID()"; At the script on Windows Form, I...
1
by: Chris | last post by:
Hi, I have jsut started to learn ASP development and have read many articles regarding which is the best to use regarding JavaScript or VBScript. All of the learning that I have done so far has...
5
by: Ankur | last post by:
Hi Folks, I am new for this group. I want to clarify one thing what's a basic difference between Client Side Java Script and Server Side Java Script. how we can differentiate it. Why we called...
35
by: Dan Rumney | last post by:
Hi all, I've been writing Javascript for quite a while now and have, of late, been writing quite a lot of AJAX and AJAX-related code. In the main, my dynamically generated pages are created...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.