Hide Next button in a multipage form

By: David Costin | Asked: 01/07/2023
ForumsCategory: Code HelpHide Next button in a multipage form
David Costin asked 2 years ago
I have a script that successfully hides the Next button when a choice is made from a radio button field. The problem is the script can only handle one choice from the radio button field. Button 1 = Red
Button 2 = Blue
Button 3 = Black
etc The script is set to 'Red' (var showVal = 'Red';). But I want the script to hide the Next button if 'Red' or 'Blue' is selected. The following script only allows one variable (var showVal = 'Red';). I have tried the command: var showVal = 'Red' OR 'Blue'. But this is not accepted (even when enclosed in brackets). <script>
jQuery(document).ready(function($){
var fieldID = 18;
var showVal = 'Red';
var $nextButton = $(".frm_button_submit"); //Hide next button by default if Red 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>
3 Answers
Victor Font answered 2 years ago

A jQuery OR is not "Red OR Blue". An OR is showVal='Red' || showVal="Blue". You could also use inArray. Initialize showVal as showVal = ['Red','Blue'], then use $.inArray($("input[name^='item_meta[" + fieldID + "]']:checked").val(), showVal) || $.inArray($("input[name^='item_meta[" + fieldID + "]']:checked").val(), showVal).

David Costin answered 2 years ago
Following your good advice I now have the following working script: -   <script> jQuery(document).ready(function($){ var fieldID = 10975; var showVal = 'Yes'; var $nextButton = $(".frm_button_submit"); //Show next button by default if Yes is checked HIDE ‘Next’ button if (($("input[name^='item_meta[" + fieldID + "]']:checked").val() != showVal) && ($("input[type=show][name^='item_meta[" + fieldID + "]']").val() != showVal)) { $nextButton.css('visibility','show'); } $("input[name^='item_meta[" + fieldID + "]']").change(function(){ if ($("input[name^='item_meta[" + fieldID + "]']:checked").val() == showVal){ $nextButton.css('visibility','hidden'); } else { $nextButton.css('visibility','visible'); } }); }); </script> I note that this relates to a Radio or Checkbox field (line 9).  Apologies for my ignorance, Im'e not sure how to change this to a Number or Text field.   David
John Ho answered 9 months ago
Hi, Im not familiar with jQuery, I was wondering how do i add this code into my form?
Victor Font replied 9 months ago

If your jQuery is for a single form, add it to the After Fields section on form's Customize HTML page. Otherwise, add it with a code snippets plugin.

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