Hiding next button based on multiple conditions

By: Luis De Pau | Asked: 06/11/2022
ForumsCategory: Code HelpHiding next button based on multiple conditions
Luis De PauLuis De Pau asked 2 years ago
Hello! This kb article shows how to hide the next button in a multi page form.   https://formidableforms.com/knowledgebase/javascript-examples/#kb-conditionally-hide-next-buttons-in-a-multi-page-form My problem is I need to hide the next button if 2 fields are empty. These are hidden fields. Is there a way to meet this condition? Thanks for any advise!
This is the script of the KB article: 

<script> jQuery(document).ready(function($){ var fieldID = 18; var showVal = 'Yes'; var $nextButton = $(".frm_button_submit"); //Hide next button by default if Yes is not already checked if (($("input[name^='item_meta[" + fieldID + "]']:checked").val() != showVal) && ($("input[type=hidden][name^='item_meta[" + fieldID + "]']").val() != showVal)) { $nextButton.css('visibility','hidden'); } $("input[name^='item_meta[" + fieldID + "]']").change(function(){ if ($("input[name^='item_meta[" + fieldID + "]']:checked").val() == showVal){ $nextButton.css('visibility','visible'); } else { $nextButton.css('visibility','hidden'); } }); }); </script>
1 Answers
Victor Font answered 2 years ago
You can add another condition to the code to check for your empty fields in this section of code: $("input[name^='item_meta[" + fieldID + "]']").change(function(){ if ( $('#empty_field1_id').val() == '' && $('#empty_field2_id').val() == '' ) { if ($("input[name^='item_meta[" + fieldID + "]']:checked").val() == showVal) { $nextButton.css('visibility','visible'); } else { $nextButton.css('visibility','hidden'); } } });
Luis De PauLuis De Pau replied 2 years ago

Thanks a lot @Victor Font !!

Making the Best WordPress Plugin even better - Together

Take on bigger projects with confidence knowing you have access to an entire community of Formidable Experts and Professionals who have your back when the going gets tough. You got this!
Join the community
crossarrow-right