Hello everyone,
I am trying to use JS to hide buttons. Basically if a checkbox is selected I want to show one box, but if the checkbox isn't selected I want it to show a different one.
So by default I have one field hidden on document load:
$('.Reject').hide();
Next is the code I am using:
function changebuttons() {
if ($("#q20 input:checked").val() == 'Yes') {
$('.Reject ').show();
$('.Approve').hide();
} else $('.Reject').hide();
$('.Approve').show();
Forgive me if there are syntax errors above, as I only copied a portion. The above code is showing the .Reject button, but is not hiding the .Approve button. Below is the entire JS I have written for this form.
//this code hides the next add another user field. It will show when one user is added.
$(document).ready(function() {
$('.Reject').hide(); //hide the Comment + Add User(s) button by default
toggleFields(); //call this first so we start out with the correct visibility depending on the selected form values
//this will call our toggleFields function every time the selection value changes
$("#q21").change(function() {
toggleFields();
});
$("#q20").change(function() {
changebuttons();
});
//this toggles the visibility of our parent permission fields depending on the current selected value
function toggleFields() {
if ($("#q21 option:selected").text() == '') $("#q25, #q22")
.hide();
else $("#q25, #q22").show();
//this code changes the button from Comment to Comment + Add User(s) if the add user to form is chosen
changebuttons(); //call this first so we start out with the correct visibility depending on the selected form values
//this will call our toggleFields function every time the selection value changes
}
function changebuttons() {
if ($("#q20 input:checked").val() == 'Yes') {
$('.Reject ').show();
$('.Approve').hide();
} else $('.Reject').hide();
$('.Approve').show();
}
});
Thanks in advance if we get a solution. Forgive me if it is a noob mistake :(