I am trying to set the value of a hidden field in a form to a static value based on a selection in a relationship dropdown in the same form. What is the best approach to achieve this?
You'll need some custom JS (or jQuery, which will be available on the page) to achieve this.
You'll want to add an event listener to the relationship dropdown to listen for when its value changes, and then update your hidden field as required when it does.
With Forms you should wait for the window.load event before running your code, so the bare bones of how you would add your code (which you can do in the Custom JS section of your form) would be something like:
window.onload = function ($) {
// your code here
$('selector for relationship dropdown').change( function(){
// value of dropdown available with $(this).val() if needed
// set value of hidden field with $('selector for hidden field').val( someValue )
});
}(jQuery);
Hi
I get the code to work for input and category select fields. The code does not work when I try it on the relationship dropdown.
When I look at the HTML code, the relationship dropdown does not look like a regular dropdown select.
What do I use as a selector in the JQuery code for the relationship dropdown?
Truls
Since it is a custom JS codes problem, if you need more assistance for it, please provide a test site with the same problem, also point out the problem page URL and form URL, I need to test and debug it in a live website, thanks