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

Question

Question

clear hidden dropdown data

asked on September 8, 2021

I would like to know how can I clear the Director Name field. My goal is when the staff selects Program radio button, every field in the Service and Executive sections gets clear.  And when the Service radio button is selected every field in the Program and Executive sections gets clear and so. The  problem I'm having is that dropdown field does not clear. Can someone tell what I need in my script.

 

directors delete.jpg
directors delete script.jpg
1 0

Replies

replied on September 8, 2021 Show version history

The problem is most likely that you're using 'input' but dropdowns are select elements, not input elements, so that code wouldn't find a match.

Assuming the programdirector class is for your dropdown, your code should look like this:

$('.programdirector select').val('');

I'd also recommend adding .change() to the end anytime you modify the value of a field using javascript to ensure everything updates properly, like so,

$('.programdirector select').val('').change();

 

However, if you're sharing classes, like you have programdirector on more than one of the inputs to group them and they are different types, then you can use the JQuery :input pseudo selector, which will find any kind of user input like textbox, radio, checkbox, dropdown, or multiline.

$('.programdirector :input').val('').change();

 

input - single line, number, currency, radio, checkbox, etc.

select - dropdown

textarea - multiline

:input - all of the above (for optimization, only use when necessary)

3 0
replied on September 8, 2021

Here a little sample using CSS classes for Radio, drop downs and Input fields

I also find you need to add the trigger('change') to get the system to accept the change made by JS if you are using lookups/field rules, etc

$(document).ready( function() {
  $('.RadioSelect input[value="choice 1"]').click(function() {
    $('.DDSelect select').val(' ');
       $('.DDSelect select').trigger('change');
    $('.FieldSelect input').val(' ');
       $('.FieldSelect input').trigger('change');
  });
});
  

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

Sign in to reply to this post.