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

Question

Question

jQuery / JS Assistance

asked on July 10, 2024 Show version history

I'm pulling data from SQL into multiple single line fields, and based on the characters in those fields, I want to set values for the single line fields that are going to be shown.

Ex: if q119 equals FP, then q120 equals Full Time, else if q119 equals PR, then q120 equals Benefited Part Time, etc.

Below is what I have, but something's wrong bc I can't seem to get it to work.

Any help would be greatly appreciated.

$(document).ready(function() {
            $('#q119 input').on('input', function() {
                var inputVal = $(this).val();
                var typeVal = '';

                if (inputVal === 'FP') {
                    typeVal = 'full time';
                } else if (inputVal === 'PR') {
                    typeVal = 'benefited';
                } else {
                    typeVal = '';
                }

                $('#q120 input').val(typeVal);
            });
        });

 

0 0

Answer

SELECTED ANSWER
replied on July 10, 2024 Show version history

Bill,

Is there a reason you are using the '===' instead of '==' in the if/else logic?  '===' means equality without type coersion and is stricter than '=='.

Also just noticed that you are triggering on an 'input' event.  I typically trigger on a 'change' event after populating the field from a lookup.

1 0
replied on July 11, 2024

You should generally always use '===' in JS because it removes all doubt from the reader's persepective on what the type of the variables being compared is. In this case jQuery's .val will always return a string so '===' is fine here.

 

I think your second point could be the issue, but technically speaking it should work on the last invoke of onInput.

 

@████████ Is this form a classic designed form or is it built in the new designer?

0 0
replied on July 11, 2024 Show version history

@████████

Thanks for responding.  I guess you could say we're on classic design.  We're still on Forms 10.4.  I left the '===' as is, but changed the input to a change event, like @████████ suggested, and that fixed it.

$(document).ready(function() {
            $('#q119 input').change(function(){
                var inputVal = $(this).val();
                var typeVal = '';

                if (inputVal === 'FP') {
                    typeVal = 'FULL TIME';
                } else if (inputVal === 'PR') {
                    typeVal = 'BENEFITED PART TIME';
                } else if (inputVal === 'PT') {
                    typeVal = 'NON-BENEFITED PART TIME';
                } else if (inputVal === 'SE') {
                    typeVal = 'SEASONAL';
                } else if (inputVal === 'BD') {
                    typeVal = 'BOARD MEMBER';  
                } else {
                    typeVal = '';
                }

                $('#q122 select').val(typeVal);
            });
        });

Thank you all for your support!

2 0

Replies

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

Sign in to reply to this post.