Avatar of Lanmarkian
Lanmarkian
 asked on

Hidden Form Fields Showing up in Error Correction

I have a form in aspx (clients request - do not know a ton about it, but am getting by). They have a checkbox that IF checked, it shows another row of form fields.

If they DON'T check the box, that's fine. The other form fields do not show up. All fields, hidden or not, have error correction.

What I am looking to do is if the box is NOT checked, then I do NOT want the error correction to function as if those fields were visibile.

How can I get past this?
ASPJavaScript

Avatar of undefined
Last Comment
Paul MacDonald

8/22/2022 - Mon
leakim971

function Validate() {
     //if(document.getElementById("myCheckbox").checked) {
     if(document.getElementById("myCheckbox").checked == true) {
          // here your current code for Error Correction (return false if fail)
          // here your current code for Error Correction (return false if fail)
          // here your current code for Error Correction (return false if fail)
      }
     return true;
}

Open in new window


<form onsubmit="return Validate()"
Paul MacDonald

The obvious thing to do would be to wrap the error correction (detection?) in an IF statement conditional on the checkbox being checked...

IF checkbox.checked THEN
  ...
  check optional fields
  ...
END IF
Lanmarkian

ASKER
All that does is look at 1 checkbox for an error. Not hidden form fields. The checkbox triggers other form fields to appear.

If the checkbox is not selected, then I don't want error correction checking those fields.
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23
ASKER CERTIFIED SOLUTION
Paul MacDonald

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Lanmarkian

ASKER
Can you help a litle further? Here is the code that is "Hidden" as well as the checkbox.

<tr id="mailme"><td colspan="10" align="center" valign="middle" style="padding-top: 5px;">
  <table><tr><td><span style="font-family: 'compacta_bd_btbold'; font-size: 19px; color: white; margin-right: 8px;">PLEASE MAIL ME A COPY </span></td><td><input name="mailcopy" type="checkbox" id="mailcopy" style="display: table-cell;"/></td></tr></table></td></tr>
    
     <tr id="physicaladdress" style="display: none;">
    <td align="right" style="padding-top: 10px; padding-bottom: 10px;">ADDRESS 1</td>
    <td style="padding-top: 10px; padding-bottom: 10px;"><asp:TextBox runat="server" id="Address1" CssClass="txtBoxes" style="width: 113px;" ></asp:TextBox>
        <asp:RequiredFieldValidator Display="None " CssClass="errorLog" ControlToValidate="Address1" ErrorMessage="Enter your address!" text=" *" runat="server" /></td>
    <td align="right" style="padding-top: 10px; padding-bottom: 10px;">ADDRESS 2</td>
    <td style="padding-top: 10px; padding-bottom: 10px;"><asp:TextBox runat="server" id="Address2"  CssClass="txtBoxes" style="width: 156px;"></asp:TextBox></td>
    <td align="right" style="padding-top: 10px; padding-bottom: 10px;">CITY</td>
    <td style="padding-top: 10px; padding-bottom: 10px;"><asp:TextBox runat="server" ID="City" CssClass="txtBoxes"  style="width: 168px;"></asp:TextBox>
        <asp:RequiredFieldValidator Display="None" CssClass="errorLog" ControlToValidate="PracticeName" ErrorMessage="Enter your city!" text=" *" runat="server" /></td>
    <td align="right" style="padding-top: 10px; padding-bottom: 10px;">STATE</td>
    <td style="padding-top: 10px; padding-bottom: 10px;"><asp:TextBox onchange="insertNow();" runat="server" ID="State" CssClass="txtBoxes"  style="width: 140px;"></asp:TextBox>
         <asp:RequiredFieldValidator Display="None" CssClass="errorLog" ControlToValidate="Email" ErrorMessage="Enter your state!" text=" *" runat="server" /></td>
    <td align="right" style="padding-top: 10px; padding-bottom: 10px;">ZIP<br />(U.S. only)</td>
    <td style="padding-top: 10px; padding-bottom: 10px;"> <asp:TextBox onchange="insertNow();" runat="server" ID="zipcode" CssClass="txtBoxes" MaxLength="10" style="width: 85px;" ></asp:TextBox>
            <asp:RequiredFieldValidator Display="None" CssClass="errorLog" ControlToValidate="pnumber" ErrorMessage="Enter your zip code!" text=" *" runat="server" /></td>
  </tr>

Open in new window

Paul MacDonald

I'm not sure what you need help with, but I changed the checkbox to add runat="server":

<tr id="mailme">
  <td colspan="10" align="center" valign="middle" style="padding-top: 5px;">
    <table>
      <tr>
        <td>
          <span style="font-family: 'compacta_bd_btbold'; font-size: 19px; color: white; margin-right: 8px;">PLEASE MAIL ME A COPY </span>
        </td>
        <td>
          <input name="mailcopy" type="checkbox" id="mailcopy" runat="server" style="display: table-cell;"/>
        </td>
      </tr>
    </table>
  </td>
</tr>
    
<tr id="physicaladdress" style="display: none;">
  <td align="right" style="padding-top: 10px; padding-bottom: 10px;">ADDRESS 1</td>
  <td style="padding-top: 10px; padding-bottom: 10px;">
    <asp:TextBox runat="server" id="Address1" CssClass="txtBoxes" style="width: 113px;" ></asp:TextBox>
    <asp:RequiredFieldValidator Display="None " CssClass="errorLog" ControlToValidate="Address1" ErrorMessage="Enter your address!" text=" *" runat="server" />
  </td>
  <td align="right" style="padding-top: 10px; padding-bottom: 10px;">ADDRESS 2</td>
  <td style="padding-top: 10px; padding-bottom: 10px;">
    <asp:TextBox runat="server" id="Address2"  CssClass="txtBoxes" style="width: 156px;"></asp:TextBox>
  </td>
  <td align="right" style="padding-top: 10px; padding-bottom: 10px;">CITY</td>
  <td style="padding-top: 10px; padding-bottom: 10px;">
    <asp:TextBox runat="server" ID="City" CssClass="txtBoxes"  style="width: 168px;"></asp:TextBox>
    <asp:RequiredFieldValidator Display="None" CssClass="errorLog" ControlToValidate="PracticeName" ErrorMessage="Enter your city!" text=" *" runat="server" />
  </td>
  <td align="right" style="padding-top: 10px; padding-bottom: 10px;">STATE</td>
  <td style="padding-top: 10px; padding-bottom: 10px;">
    <asp:TextBox onchange="insertNow();" runat="server" ID="State" CssClass="txtBoxes"  style="width: 140px;"></asp:TextBox>
    <asp:RequiredFieldValidator Display="None" CssClass="errorLog" ControlToValidate="Email" ErrorMessage="Enter your state!" text=" *" runat="server" />
  </td>
  <td align="right" style="padding-top: 10px; padding-bottom: 10px;">ZIP<br />(U.S. only)</td>
  <td style="padding-top: 10px; padding-bottom: 10px;">
    <asp:TextBox onchange="insertNow();" runat="server" ID="zipcode" CssClass="txtBoxes" MaxLength="10" style="width: 85px;" ></asp:TextBox>
    <asp:RequiredFieldValidator Display="None" CssClass="errorLog" ControlToValidate="pnumber" ErrorMessage="Enter your zip code!" text=" *" runat="server" />
  </td>
</tr>

Open in new window


Then, in your codebehind, wherever you're doing your error checking...
IF mailcopy.checked THEN
...do conditional errorchecking...
END IF

...do regular errorchecking...

Open in new window