mercredi 3 juin 2015

Disable control based on value returned from database

I have an ASP page that displays a list of contacts with an edit button next to each contact. When i click on the edit button, it resubmits the form and displays detailed information about the selected contact. The control 'ContactType is a dropdown box with contact types in them. Another control is a checkbox 'CMP' that based on what value is selected in the ContactType control the checkbox is either enabled or disabled. I can get this functionality to work if the the dropdowns value is changed using a call to a javascript function on the OnChange event of the ContactType control but when the value is initially set, the onChange event does not fire. So if the contact that is selected has a contact type where the checkbox should be disabled when the form is rendered, the checkbox is not disabled. How do i set the 'CMP'controls disabled attribute to true/false based on the contact that was selected? Any help you can give me would be appreciated. This is classic ASP. I have attached the pertinent code below.

    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

Here is the 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">&nbsp;&nbsp;
                        <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">&nbsp;&nbsp;
                        <input type="checkbox" name="CMP" id="CMP" class="CMP" value="1" <% if CMP = 1 then response.write "checked='Checked'" end if %> />
                    </td>
                </tr>

                  

. . .

Aucun commentaire:

Enregistrer un commentaire