Hi there - I currently have a form that populates a text field (field_lx21m) with a value based on 3 other fields that a user can fill out. I am trying to use the value of the text field to then populate a lookup field (field_f3s8k) from the code in the help docs.
The code I am using is below. The text field looks like it populates correctly. However, the value does not seem to be copying to the lookup field at all. Any help would be much appreciated!
jQuery(document).ready(function($) {
var field_i12n_value = $('#field_i12n').val();
var field_aw49p_value = $('#field_aw49p').val();
var field_iqa64_value = $('#field_iqa64').val();
// Checking conditions and copying values
if (field_i12n_value !== '') {
$('#field_lx21m').val(field_i12n_value);
} else if (field_aw49p_value !== '') {
$('#field_lx21m').val(field_aw49p_value);
} else if (field_iqa64_value !== '') {
$('#field_lx21m').val(field_iqa64_value);
} else {
// If none of the conditions are met, keep field_f3s8k empty or handle as needed
$('#field_lx21m').val(field_iqa64_value);
}
// Trigger custom event after the conditionals
$('#field_lx21m').change(function(){
var sourceField = $('#field_lx21m').val();
$('#field_f3s8k').val(sourceField);
$('#field_f3s8k').trigger({ type:'change', originalEvent:'custom' });
});
});
What kind of lookup field are you using, Dynamic or Lookup? Both of these show values from a lookup table, but how you interact with them at a code level is completely different. The code you show above is just jQuery. All it does is interact with the fields on the form. It has nothing to do with saving a value to a lookup table. Depending on your form and lookup designs, there maybe different things you may have to do in PHP to complete your requirement. You need to provide more details about your design so we can help with a solution.
Please login or Register to submit your answer