请问在ASP中怎样实现服务器端变量与客户端变量的交互??

不懂王 国家电网南瑞集团公司 开发组长/高级工程师/技术专家  2002-08-01 10:53:37
请问如何将<% %>中的数组变量的值传给客户端 javascript 中的数组??
...全文
43 点赞 收藏 2
写回复
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
yonghengdizhen 2002-08-01
同意楼上的..

我有一段这样的代码用于下拉框级联修改的:
另外使用隐含域也不失为一种好的方法.

<!--#INCLUDE FILE="../../FUNCTIONS/PUBLIC_FUNCTIONS.ASP"-->
<!--#INCLUDE FILE="../../FUNCTIONS/OOCL_FUNCTIONS.ASP"-->
<!--#INCLUDE FILE="../INCLUDES/LOCAL_VARIABLES.ASP"-->
<!--#INCLUDE FILE="../INCLUDES/AUTHENTICATE.ASP"-->
<%
HTMLTitle=strHtmlTitlePrefix&" (Change-Reporting party)"
Response.Write GenHtmlHeader(HTMLTitle,strCSSPath & "pagestyle.css")
%>
<!--#INCLUDE FILE="../INCLUDES/TOP_HTML.ASP"-->
<script language=javascript src="../../functions/functions.js"></script>
<script language=javascript src="../includes/common.js"></script>
<form name="CENavigite" method="POST" action="../REVIEW/CAPTIAL_EXPENDITURE_VIEW_REPORTING_PARTY.ASP">
<%
Dim oConn,oRs,strSQL
strSQL="(SELECT report_gp_record_no,reporting_group.report_group,0 AS groupid,''"
strSQL=strSQL & " FROM reporting_group WHERE show_to_user=1)"
strSQL=strSQL& " UNION (SELECT report_entity_record_no,reporting_entity,report_group AS groupid,lco"
strSQL=strSQL & " FROM reporting_entity WHERE show_to_user=1"
strSQL=strSQL & " AND report_group IN"
strSQL=strSQL & "(SELECT report_gp_record_no FROM reporting_group WHERE show_to_user=1))"
strSQL=strSQL & "ORDER BY groupid ASC"
If ConnectDB("[Master DSN Name]",oConn,false) Then
set oRs=Server.CreateObject("ADODB.Recordset")
oRs.Open strSQL,oConn
if Err.number<>0 then
Set oRs=Nothing
bOOCLIsErr=true
strOOCLErrMsg=strOOCLErrMsg & arrUnknowErr(2)
else
%>
<table width="100%" cellspacing="2" cellpadding="1">
<tr>
<td width="40%">Company:</td>
<td width="60%"><%=dfTextToHTML(Request.Form("CompanyName"))%>
</td>
</tr>
<tr>
<td width="40%">Last Updating Party:</td>
<td width="60%"><%=dfTextToHTML(Request.Form("LastUpdateBy"))%></td>
</tr>
<tr>
<td width="40%">Last Updating on:</td>
<td width="60%"><%=dfFormatDate(Request.Form("LastUpdateOn"))%></td>
</tr>
<tr>
<td width="40%">Form Status:</td>
<td width="60%">
<%if Request.Form("FormStatus") then Response.Write "Confirm" else Response.Write "Save" end if%>
</td>
</tr>
<tr>
<td colspan=2>
<!--用于随后的页显示,而不需向数据库再次查询-->
<input type=hidden name=companyname value="<%=dfTextToHTML(Request.Form("CompanyName"))%>">
<!--用于在页面间切换时保留查询参数-->
<input type=hidden name=PeriodFrom value=<%=Request.Form("PeriodFrom")%>>
<input type=hidden name=PeriodTo value=<%=Request.Form("PeriodTo")%>>
<!--从Capital_Expenditure_Header查询出来的信息,在页面间的切换始终保持-->
<input type=hidden name=CapitalId value=<%=Request.Form("CapitalId")%>>
<input type=hidden name=ReportEntityId value=<%=Request.Form("ReportEntityId")%>>
<input type=hidden name=ReportingParty value="<%=dfTextToHTML(Request.Form("ReportingParty"))%>">
<input type=hidden name=Remarks value="<%=dfTextToHTML(Request.Form("Remarks"))%>">
<input type=hidden name=LastUpdateBy value=<%=dfTextToHTML(Request.Form("LastUpdateBy"))%>>
<input type=hidden name=LastUpdateOn value="<%=Request.Form("LastUpdateOn")%>">
<input type=hidden name=FormStatus value="<%=Request.Form("FormStatus")%>">
<!--用于分页功能进行分页判断-->
<input type=hidden name=category value="<%=Request.Form("category")%>">
</td>
</tr>
</table>
<table width="100%" cellspacing="2" cellpadding="1">
<tr height=20>
<td width="30%" class=off style="cursor:hand" onclick="GoPage('../REVIEW/CAPTIAL_EXPENDITURE_VIEW_A_N_C.ASP')">Authorized but not contracted for</td>
<td width="30%" class=off style="cursor:hand" onclick="GoPage('../REVIEW/CAPTIAL_EXPENDITURE_VIEW_A_C.ASP')">Authorized and contracted for</td>
<td width="20%" class=off bgcolor=DDE9F9>Reporting party</td>
<td width="10%" class=off style="cursor:hand" onclick="GoPage('../REVIEW/CAPTIAL_EXPENDITURE_VIEW_REMARKS.ASP')">Remarks</td>
<td width="20%" class=off style="cursor:hand" onclick="GoPage('../REVIEW/CAPTIAL_EXPENDITURE_VIEW_HISTORY_LOG.ASP')">History log</td>
</tr>
</table>
<BR>
<table width="100%" cellspacing="2" cellpadding="1" align=center>
<%
if not oRs.EOF then
dim LCO,strSelect,ResultArray,i,j,k
ResultArray=oRs.GetRows()
oRs.close
FreeDBRes
%>
<tr>
<td nowrap width=30%>Reporting Group:</td>
<td width=70%>
<%
if IsArray(ResultArray) then
%>
<input type=checkbox onclick="ModifyCtrl()"><select style="width:190px" id=NewGroupId name=NewGroupId class=input disabled onchange="SelectGroup()">
<%
for i=Lbound(ResultArray,2) to Ubound(ResultArray,2)
if ResultArray(2,i)>0 then exit for
if ResultArray(0,i)=Cint(Request.Form("groupid")) then strSelect=" selected"
%>
<option value="<%=ResultArray(0,i)%>"<%=strSelect%>><%=dfTextToHTML(ResultArray(1,i))%></option>
<%
strSelect=""
next
%>
</select>
<%
end if
k=i
%>
</td>
</tr>
<tr>
<td nowrap>Reporting Entity:</td>
<td>
<%
if IsArray(ResultArray) then
%>
<input type=checkbox onclick="ModifyCtrl()"><select style="width:190px" class=input disabled id=NewReportEntityId onchange="SelectItem()">
<%
for i=k to Ubound(ResultArray,2)
if ResultArray(2,i)=Cint(Request.Form("groupid")) then
if ResultArray(0,i)=CInt(Request.Form("ReportEntityId")) then
strSelect=" selected"
LCO=ResultArray(3,i)
end if
%>
<option value="<%=ResultArray(0,i)%>"<%=strSelect%>><%=dfTextToHTML(ResultArray(1,i))%></option>
<%
strSelect=""
end if
next
%>
</select>
<SCRIPT>
var JsResultArray=new Array(<%=Ubound(ResultArray,2)%>)
for(i=0;i<JsResultArray.length;i++)
{
JsResultArray[i]=new Array(<%=Ubound(ResultArray,1)+1%>)
}
<%
for i=k to Ubound(ResultArray,2)
for j=1 to Ubound(ResultArray,1)+1
%>
JsResultArray[<%=i-k%>][<%=j-1%>]="<%=dfTextToHTML(ResultArray(j-1,i))%>"
<%
next
next
%>
</SCRIPT>
<%
end if
%>
</td>
</tr>
<tr>
<td nowrap>LCO:</td><td id=LCO><%=dfTextToHTML(LCO)%></td>
</tr>
<tr>
<td nowrap>Reporting Party:</td>
<td>
<input type=checkbox onclick="selectbtn.disabled=!selectbtn.disabled;ModifyCtrl()"><input onkeypress="return false;" class=input id=NewReportingParty disabled value="<%=dfTextToHTML(Request.Form("ReportingParty"))%>">
<input type=button value="Select" id=selectbtn class=btn disabled
onclick="dfOpenURL('../SEARCH/CAPTIAL_EXPENDITURE_SELECT_REPORTING_PARTY.ASP'),450,400">
</td>
</tr>
<%
else
bOOCLIsErr=true
strOOCLErrMsg=strOOCLErrMsg & arrCommMsg(13)
strOOCLErrMsg=strOOCLErrMsg & "<BR>" & arrCommMsg(14)
end if
%>
</table>
<BR>
<table>
<tr height=30>
<td align=center>
<input class=btn type=button value="Back" onclick="GoPage('../REVIEW/CAPTIAL_EXPENDITURE_VIEW_REPORTING_PARTY.ASP')">
<%if Not Request.Form("FormStatus") then%><input class=btn type=submit value="Save" name=SaveUpdate><%end if%>
<input class=btn type=submit value="Confirm" name=ConfirmUpdate onclick="GoPage('../REVIEW/CAPTIAL_EXPENDITURE_VIEW_REPORTING_PARTY.ASP')">
</td>
</tr>
</table>
<%
end if
else
bOOCLIsErr=true
strOOCLErrMsg=strOOCLErrMsg & arrUnknowErr(0)
End If
FreeDBRes
if bOOCLIsErr Then Response.Write strOOCLErrMsg
%>
</form>
<!--#INCLUDE FILE="../INCLUDES/BOTTOM_HTML.ASP"-->
回复
ChinaOk 2002-08-01
try

<SCRIPT LANGUAGE=javascript>
var aryJS=new Array("<%=jion(aryASP,""",""")%>");
回复
发动态
发帖子
ASP
创建于2007-09-28

2.8w+

社区成员

ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
申请成为版主
社区公告
暂无公告