The Community forums are being phased out in favor of a new Slack group.
Add your email address below to get an invitation to join the community slack group

Slack Signup
Newsletter Optin
Help Desk

Text, not ID.

Labels

This Discussion is public

Notifications

I followed the snippet here: https://formidableforms.com/knowledgebase/javascript-examples/#kb-dropdown-fields

It basically works but inserts the entry ID instead of the text from the dropdowns. Any clues?

You haven't given us enough to go on. The example is  nice, but Javscript is very specific to your form. Please post a link to your form and explain in more detail what you're trying to accomplish.

Thanks Victor. There are two dynamic dropdowns that choose options from two other forms. As attached, the text in the selections should display in the text field 'Route details'. Instead of showing the text (YPKA and XOAP), the text field shows the ID's of the options entries (91 and 97). Do you see my problem now?

Here is the code:

<script type="text/javascript">
jQuery(document).ready(function($){
$(document).on('change', 'select[name="item_meta[200]"], select[name="item_meta[202]"]', function(){
var val1 = $("select[name='item_meta[200]']").val();
var val2 = $("select[name='item_meta[202]']").val();
$("#field_n4cyt").val(val1+' '+val2);
});
});
</script>

 


Attachment:

I understand now. The Dynamic Dropdown fields do use the lookup entry ID as the select value. The only way around this is to re-populate the fields with the frm_setup_new_fields_vars filter when the entry is created.  In your code, which is added to functions.php, you copy the arrays value into its key. Here's an example based on the details you provided above:

add_filter('frm_setup_new_fields_vars', 'change_select_values', 20, 3);
function change_select_values($values, $field){
if($field->id == 200 || $field->id == 202) {
$temp_options = array();
foreach($values['options'] as $key => $value){
$temp_options[$value] = $value;
}
$values['options'] = $temp_options;
}
return $values;
}

If anything, you may have to change the field ids to match your actual field ids.

add_filter('frm_setup_new_fields_vars', 'change_select_values', 20, 3);
function change_select_values($values, $field){
if($field->id == 200 || $field->id == 202) {
$temp_options = array();
foreach($values['options'] as $key => $value){
$temp_options[$value] = $value;
}
$values['options'] = $temp_options;
}
return $values;
}

Discussion closed.