我有一个ASP页面,显示一个联系人列表,每个联系人旁边都有一个编辑按钮。当我单击编辑按钮时,它会重新提交表单并显示有关所选联系人的详细信息。控件'ContactType是一个下拉框,其中包含联系人类型。另一个控件是一个复选框'CMP',它基于在ContactType控件中选择的值,启用或禁用复选框。如果通过调用ContactType控件的OnChange事件上的javascript函数来更改下拉列值,则可以使此功能正常工作,但是当初始设置该值时,onChange事件不会触发。因此,如果所选的联系人具有联系人类型,其中在呈现表单时应禁用该复选框,则不会禁用该复选框。如何根据所选的联系人将'CMP'controls disabled属性设置为true / false?你能给我的任何帮助将不胜感激。这是经典的ASP。我附上了下面的相关代码。
elseif Request("hdnSelect") = "True" then
'Select CustomerContact to edit
SQL = "dbo.GetCustomerContactInfobyContactID '" & sqlsafe(request("hdnWhichOne")) & "'"
set rsSelect = objDBConn.execute(SQL)
if not rsSelect.EOF then
ContactType = rsSelect("Contact_TypesID")
Name = rsSelect("Name")
Number = rsSelect("Number")
AltNumber = rsSelect("AltNumber")
EmailAddress = rsSelect("EmailAddress")
Notes = rsSelect("Notes")
FName = rsSelect("ContactFName")
LName = rsSelect("ContactLName")
Title = rsSelect("Title")
CMP = iif(rsSelect("CMP") = "True", "1","0")
//if the value of CMPEligable is false Disable the 'CMP' control otherwise enable it.
if (rsSelect("CMPEligable") = "False") then
CMP = 0
'this is where i need to set the 'CMP' controls disabled attribute to true
else
'this is where i need to set the 'CMP' controls disabled attribute to false
end if
end if
selectedID = request("hdnWhichOne")
bEditMode = True
elseif Request("hdnUpdate") = "True" then
这是HTML
<form method="post" action="AddCustomerContact.asp?action=submit" name="c">
<input type="hidden" name="sid" value="<%=Request("sid") %>" />
<input type="hidden" name="cid" value="<%=Request("cid") %>" />
<input type="hidden" name="hdnCancel" value="False" />
<input type="hidden" name="hdnSelect" value="False" />
<input type="hidden" name="hdnUpdate" value="False" />
<input type="hidden" name="hdnAdd" value="False" />
<input type="hidden" name="hdnDelete" value="False" />
<input type="hidden" name="hdnWhichOne" value="" />
<input type="hidden" name="hdnCMPEligable" value="" />
<table border="0" cellpadding="2" cellspacing="2" width="100%">
.
.
.
<input type="hidden" name="selectedID" value="<%= selectedID %>" />
<table border="0" cellpadding="2" cellspacing="2" width="100%">
<tr>
<td colspan="2" class="corpCopy"><br /><b>Edit Customer Contact</b></td>
</tr>
<tr>
<td>
<table border="0">
<tr>
<td align="right" width="180"><b><span class="corpCaption"><b>Contact Type:</b></span></b></td>
<td align="left">
<select name="ContactType" id="ContactType" onchange="javascript:displayCMP(this.selectedIndex);">
<!--onchange="javascript:saveSalesChannel(this);">-->
<option value="">* Select *</option>
<%
dim contacttypeid
If request("sid") <> "" Then
SQL = "dbo.proc_Contact_Types_GetbyselectedID " & selectedID
set rscontactTypes = objDBConn.execute(SQL)
if not rscontactTypes.EOF then
contacttypeid = rscontactTypes("Contact_TypesID")
end if
End If
If contacttypeid = "" Then
contacttypeid = ""
end if
SQL = "dbo.proc_Contact_Types_GetAll"
set rsCT = objDBConn.execute(SQL)
Do While Not rsCT.EOF
if rsCT("isActive") = True then
Response.Write "<option value='" & rsCT("id") & "-" & rsCT("CMPEligable") & "'"
if rsCT("id") = contacttypeid then
Response.Write " selected"
end if
Response.Write ">" & rsCT("Type") & "</option>"
else
if rsCT("id") = contacttypeid then
Response.Write "<option value='" & rsCT("id") & "-" & rsCT("CMPEligable") & "' selected>" & rsCT("Type") & "</option>"
end if
end if
rsCT.movenext
Loop
rsCT.Close
set rsCT = nothing
%>
</select>
</td>
.
.
.
.
<tr>
<td align="right" valign="top"><b><span class="corpCaption"><b>CMP:</b></span></b></td>
<td align="left" valign="top">
<input type="checkbox" name="CMP" id="CMP" class="CMP" value="1" <% if CMP = 1 then response.write "checked='Checked'" end if %> />
</td>
</tr>
。 。
答案 0 :(得分:0)
我能够找到自己对自己问题的答案。我添加了一个隐藏的控件,当选择联系人并运行存储过程以获取联系人的详细信息时,我根据查询返回的CMPEligable标志设置隐藏的控件值。
SQL = "dbo.GetCustomerContactInfobyContactID '" & sqlsafe(request("hdnWhichOne")) & "'"
set rsSelect = objDBConn.execute(SQL)
if not rsSelect.EOF then
ContactType = rsSelect("Contact_TypesID")
Name = rsSelect("Name")
Number = rsSelect("Number")
AltNumber = rsSelect("AltNumber")
EmailAddress = rsSelect("EmailAddress")
Notes = rsSelect("Notes")
FName = rsSelect("ContactFName")
LName = rsSelect("ContactLName")
Title = rsSelect("Title")
CMP = iif(rsSelect("CMP") = "True", "1","0")
if (rsSelect("CMPEligable") = "True") then
hdnCMPEligable = "True"
else
CMP = 0
hdnCMPEligable = "False"
end if
end if
然后在我的html i中渲染表单时,我检查隐藏控件的值并适当地设置disabled属性。
<td align="left" valign="top">
<input type="checkbox" name="CMP" id="CMP" class="CMP" value="1" <% if CMP = 1 then response.write "checked='Checked'" end if %> <% if hdnCMPEligable = "False" then response.write " disabled='True' " end if %> />
</td>