Home > database >  Hidden checkbox required to be checked even when hidden
Hidden checkbox required to be checked even when hidden

Time:04-28

I’m kinda of stuck.

I’m using html5 required for a very simple validation, and I have a checkbox that only shows up if you meet some conditions. You then have to agree with terms and check the checkbox.

The problem is when you don’t hit conditions and checkbox reminds hidden then its not posible to submit. It should only be required if you see it.

.terms{
display: none;
}

<form>

<p><input  type="checkbox" id="checkId" required>Terms & Conditions</p>
<input type="submit" name="submit" value="Submit" id="submit" />

</form>

CodePudding user response:

This will work

<form>
<p><input  type="checkbox" id="checkId" name="checkId" checked style="visibility: hidden;">Terms & Conditions</p>
<input type="submit" name="submit" value="Submit" id="submit" />

</form>
  • Related