Conditional Default Values for Dropdown Menus

Labels

This Discussion is public

Notifications

Hey there,

Has anyone had any experience setting a default value for a dropdown field (with separate labels / values) conditional upon the option selected from another dropdown?

In other words, when the user selects an option from Dropdown [123], Dropdown [789] will be "autopopulated" with a value based on what was chosen in [123].

From what I have gathered, it is not a normal feature of formidable and requires custom JavaScript.

I have been trying to a function with conditional statements as follows:

jQuery(document).ready(function($){
$('select[name="item_meta[123]"]').change(function(){
var val1 = $("select[name='item_meta[123]']").val();
if (val1 == "Option 1")
{$("select[name='item_meta[789]']").val(5);}
else if (val1 == "Option 2")
{$("select[name='item_meta[789]']").val(10);}
$("select[name='item_meta[789]']").change();
});
});

The problem is that my dropdown menu [789] has separate labels / values. If the dropdown did not have separate values it would work perfectly. However, I cannot remove the separate values as I need them for another purpose. As it stands, no label gets selected on [789] once [123] has been changed.

Any ideas?

Thanks in advance!