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>
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).
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
Please login or Register to submit your answer