Get label from drop down in separate text box?

By: Peter Walters | Asked: 11/22/2022
ForumsCategory: Code HelpGet label from drop down in separate text box?
Peter Walters asked 1 year ago

Hi all,

So I have a dropdown product field with various options and labels (think that's the terminology) So the option is 'Top Fuel Dragster', the price is '50' and the label is 'TF'

Using the below code, I have managed to display 'Top Fuel Dragster' in a separate text box.

<script type="text/javascript">
jQuery(document).ready(function($){
$(document).on('change', 'select[name="item_meta[125]"]', function(){
var val1 = $("select[name='item_meta[125]']").children("option").filter(":selected").text().trim();
$("#field_FIELDKEY").val(val1);
$("#field_FIELDKEY").change();
});
});
</script>

Does any one know if there is a piece of code that will display the label 'TF' instead in another text box? I can't work out how to do it. 

Alternatively (and my preferred option) is there an 'if then that' piece of code that will display a value if a text box contains the right thing?

So if textbox 1 contains 'Top Fuel Dragster' > display 'TF' in textbox 2

Thanks in advance

Attachments
1 Answers
Bobby Clapp answered 1 year ago
Try this, instead of using jQuery, make the text field a calculation field of text and put this in there [x show="value"]. X should be the field ID of the dropdown. Seems like that should work.
Peter Walters replied 1 year ago

Thanks Bobby, but that just shows the price in the field, rather than the text.

Bobby Clapp replied 1 year ago

What does just the ID show versus "show value"?

Peter Walters replied 1 year ago

Just the ID also shows the price, which doesn't seem right to me!

Bobby Clapp replied 1 year ago

Right? Seems odd. This is a woocommerce product?

Peter Walters replied 1 year ago

No, just added within the form. Not linked to Woocommerce or anything. Just the simple 'Product field' as a dropdown

Making the Best WordPress Plugin even better - Together

Take on bigger projects with confidence knowing you have access to an entire community of Formidable Experts and Professionals who have your back when the going gets tough. You got this!
Join the community
crossarrow-right