K
Kathryn
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("RunStructureName")%></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.
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("RunStructureName")%></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.