You are viewing limited content. For full access, please sign in.

Question

Question

Making a Field Required based on a Previous Radio Button Value

asked on May 30, 2019

Hello,

 

I am having some issues with the JavaScript that is in many posts to make a field required based on a previous value.

$(document).ready(function () {
    $('#q1 input').change(function () {
        if ($(this).val()=="Yes") {
            $('#q17 label').append('<span class="cf-required">*</span>');
            $('#q17 input').attr('required', 'True');
        } else {
          
       $('#q17 span.cf-required').remove();
            $('#q17 input').removeClass('required').removeAttr('required');

        }
    })
});

This issue I have is that it not only makes the question required but it also make both the radio button value required.

The way I want my process to work is that if the "Is there an abstract available for this property?" is answered yes then the question "Is this replacing an existing abstract?" needs to be required.

 

I have the field set to required and have it hidden (with field rules) until the available question is answered Yes.

 

Where the trouble is coming in is that I need to save the data from both fields even when they are hidden.  So even if they choose No on the first question, if I leave validation on, it won't let them submit because it still says question 2 is required even though it is not shown.

 

So I tried to make the field required through JavaScript but that is where it is making too much of it required.  How do I alter the script to not make the radio button values required.

 

Hope this make a little bit of sense.

 

Thanks.

 

RequiredField.png
0 0

Replies

replied on May 31, 2019 Show version history

Hi Jennifer,

Edit sorry re reading this. Can you not set the second question to default to no? so even when hidden it still contains a value.

Thanks

Mark

 

 

0 0
replied on May 31, 2019

That is a good thought.  I never thought of just making one option the default.

 

I ended up using a work around of having another hidden field with a calculation and did the show/hide rules using the calculation field.

 

Thanks.

 

0 0
You are not allowed to follow up in this post.

Sign in to reply to this post.