How do I validate Radio Buttons for the Unbounce Platform using Jquery?

246 Views Asked by At

I'm trying to setup a contact form for a Landing Page where leads have to click on "Yes" to having read the terms of service. It would be much easier to simply have an "I accept" checkbox as opposed to "Yes" and "No" Radio Buttons but unfortunately thats what has been asked of me. I'm using Unbounce as a platform. Could someone please help me write out the code? Thanks :)

  lp.jQuery(function($) {

      // Config
    var ruleID = 'I have read the TOS';
    var field = 'terms_of_service';
    var message = 'Please confirm you have read the Terms of Service by clicking YES';

    var rules = module.lp.form.data.validationRules[field];

...
1

There are 1 best solutions below

0
jiwopene On

This is code to check if radio button or checkbox is checked. Remember you must add checked HTML attribute to "No" so it is checked by default.

function check() {
  if ($("#yesb").prop("checked")) {
    console.log("Accepted!");
  }
  else {
    console.log("Not accepted. :-(");
  }
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

<label><input name=accepted type=radio id=yesb>Yes</label>
<label><input name=accepted type=radio id=nob checked>No</label>

<button onclick=check()>Check</button>