Last active
January 23, 2018 14:46
-
-
Save sebas932/7b1cba272db2c51d88241951771eafc8 to your computer and use it in GitHub Desktop.
Revisions
-
sebas932 revised this gist
Jan 23, 2018 . 1 changed file with 2 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,2 @@ <script src="https://code.jquery.com/jquery-1.12.4.min.js" integrity="sha256-ZosEbRLbNQzLpnKIkEdrPv7lOy9C27hHQ+Xp8a4MxAQ=" crossorigin="anonymous"></script> <script type="text/javascript" src="validation_form1.js" ></script> -
sebas932 created this gist
Jan 23, 2018 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,41 @@ var $form1, formArray1, formNames1; $(document).ready(init); function init() { // Form 1 - Radios Validation $form1 = $('input[name="p1"], input[name="p2"], input[name="p3"], input[name="p4"], input[name="p5"], input[name="p6"], input[name="p7"], input[name="p8"], input[name="p9"], input[name="p10"]'); formValues1 = []; formNames1 = []; // Event when form 1 radiobuttons is clicked $form1.on('click', function(e){ // Set parameters var isChecked = $(this).is(':checked'); var selectedValue = parseInt(this.value); var selectedName = this.name; var selectedOptions = formValues1.length; var isValueRepeated = ($.inArray(selectedValue, formValues1) != -1); var isNameRepeated = ($.inArray(selectedValue, formValues1) != -1); // Validate at least 3 options selected and no repeated if((selectedOptions < 3) && !isValueRepeated && !isNameRepeated){ // Add value TO formValues1 if(!isValueRepeated){ formValues1.push(selectedValue); } if(!isNameRepeated){ formNames1.push(selectedName); } }else{ // Do nothing e.preventDefault(); } console.log(formValues1); console.log(formNames1); }); }