I have a form in which I have a single item I want to be conditional IF another form element’s value is “yes”.
I thought I understood how to access html items using the designer API, but I’m obviously doing something wrong given that it won’t work.
My code is:
if (query(“#severeReaction”).value == “yes”) {
results.show();
} else {
results.attr(“data-conditional”, “”);
results.hide();
}
I am trying to access that select element (id of severe reaction) and, if the selected option’s value is yes, show the conditional form element. Am I missing something?
Thank you in advance for any and all help offered,
Depends if you want to have the content change dynamically (for instance, in response to the user switching an option from Yes to No) or if you simply want to have a static condition that sets visibility of the target element at load time and that doesn’t change afterwards.
But since in my template the severeReaction element is a SELECT element, it can be changed dynamically by the user. In that case, we need a client-side JS function to switch the elements dynamically:
I’ll be honest Phil, I can’t for the life of me get the conditional script to work in my case. I query an element called #severeReaction for my conditional value, and dependent on yes/no, “severeDescription” (results) should show/hide. For some reason, my div element that I’m finding by selector (#severeDescription) will not show/hide.
However, the client side JS works perfectly fine and I will use that as my solution. I appreciate your help with this.
Have you tried showing in the console the content of your #severeDescription item? Just to see if it isn’t a problem with the actual value and not the logic?
In the attached template (saved in 2018.1) I used jQuery to toggle the visibility of the reaction using a client side JavaScript.
The user script in the Designer sets the initial status based on a data field (assume this was required). Secondly I used a JavaScript (jQuery) to call a function when the value of the combo box changes. In the attached template I loaded the jQuery library from an online location (cdnjs.com, a popular content delivery network which hosts popular libraries).