Professional Web Applications Themes

Client side and server side scripting problem - ASP

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

  1. #1

    Default 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.
    Kathryn Guest

  2. #2

    Default Re: Client side and server side scripting problem

    "Kathryn" <andania1hotmail.com> wrote in message
    news:42947ac.0310150416.13292c1posting.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
    [url]http://www.iistoolshed.com/[/url] - tools, scripts, and utilities for running IIS
    [url]http://mvp.support.microsoft.com/[/url]
    [url]http://www.microsoft.com/windowsserver2003/community/centers/iis/[/url]



    Tom Kaminski [MVP] Guest

  3. #3

    Default Re: Client side and server side scripting problem

    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" <andania1hotmail.com> wrote in message
    news:42947ac.0310150416.13292c1posting.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.

    WIlliam Morris Guest

  4. #4

    Default Re: Client side and server side scripting problem



    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 [url]http://www.developersdex.com[/url] ***
    Don't just participate in USENET...get rewarded for it!
    KP Guest

  5. #5

    Default Re: Client side and server side scripting problem


    Thanks Tom!


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

  6. #6

    Default Re: Client side and server side scripting problem

    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" <anonymousdevdex.com> wrote in message
    news:#VW0ky#kDHA.1488TK2MSFTNGP12.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 [url]http://www.developersdex.com[/url] ***
    > Don't just participate in USENET...get rewarded for it!

    WIlliam Morris Guest

  7. #7

    Default Re: Client side and server side scripting problem

    Should item [0][1] be "Fairlane?" I especially like the Talladega edition.
    I wonder how many still exist. :]

    Ray at work


    "WIlliam Morris" <seamlyneNO_SP_AMhotmail.com> wrote in message
    news:bmmjt3$ohcm1$1ID-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.
    >

    Ray at Guest

  8. #8

    Default Re: Client side and server side scripting problem

    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:OUrwBoAlDHA.2232TK2MSFTNGP09.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" <seamlyneNO_SP_AMhotmail.com> wrote in message
    > news:bmmjt3$ohcm1$1ID-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.
    > >
    >
    >

    WIlliam Morris Guest

  9. #9

    Default Re: Client side and server side scripting problem


    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 [url]http://www.developersdex.com[/url] ***
    Don't just participate in USENET...get rewarded for it!
    KP Guest

  10. #10

    Default Re: Client side and server side scripting problem

    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" <anonymousdevdex.com> wrote in message
    news:#FxFDoLlDHA.3316tk2msftngp13.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 [url]http://www.developersdex.com[/url] ***
    > Don't just participate in USENET...get rewarded for it!

    William Morris Guest

Similar Threads

  1. flashcom: client side cant access server side
    By u_sq in forum Macromedia Flash Flashcom
    Replies: 1
    Last Post: June 28th, 09:16 PM
  2. Help needed with DataGrid Client-Side Scripting
    By Subba Rao via DotNetMonster.com in forum ASP.NET Data Grid Control
    Replies: 2
    Last Post: March 10th, 04:42 PM
  3. Controls with a client side onLoad function or seting a cursor server side
    By Geoff Davis in forum ASP.NET Building Controls
    Replies: 3
    Last Post: January 15th, 03:54 AM
  4. server-side ASP w/ client -side component
    By Miguel Guerreiro in forum ASP Components
    Replies: 1
    Last Post: August 5th, 12:09 AM
  5. button evet ---- server side - client side ???
    By yaya coco in forum ASP.NET General
    Replies: 1
    Last Post: July 4th, 10:58 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139