mercredi 24 mai 2017

checkbox toggle the "required" attribute on html form

my html form has an input field that is hidden whenever a checkbox is checked using this script.

function toggle(className, checkbox) {
       var $input = $(checkbox);
       if ($input.prop('checked')) $(className).hide();
       else $(className).show();
}

the thing is my input field is required, so when it's hidden i can't submit my form even if i can't see the input field.

is there a way to remove the "required" attribute when the checkbox is checked ?

Thank you :D




Aucun commentaire:

Enregistrer un commentaire