Referencing form select field

By: Tharusha Induwara | Asked: 05/30/2022
ForumsCategory: Code SnippetsReferencing form select field
Tharusha InduwaraTharusha Induwara asked 2 years ago
I have a form with a select dropdown field where the ID is field_cityname-0 and the meta name is item_meta[21][0][24]. The ID and the name were obtained using web inspect. Then the JS reference should be
document.getElementById("field_cityname-0");
But when I check the formidable form documentation, I saw the field reference, as below.
select[name='item_meta[994]']
Is it a must to use the above reference or can I use document.getElementById. I'm still new to JS so all the helpful answers are welcome.
Bobby Clapp replied 2 years ago

If you go to https://formidableforms.com/knowledgebase/javascript-examples/#kb-referencing-field-types and then scroll down to the next section on "Conditionally hide/show a field", that will give you an example of how to use the select item. That is the ideal way to reference select fields.

Tharusha InduwaraTharusha Induwara replied 2 years ago

Thanks for your answer @Bobby Clapp . What I'm doing is getting the entries from a dropdown in Formidable form and using those entries I want to create markers on google maps. So can I get the values from form fields, by using another external script file?

Bobby Clapp replied 2 years ago

Wrap this in script tags:

jQuery('select[name='item_meta[994]']').on('change', function() {
alert( this.value );
});

Change the 994 to your field ID. This is a short simple example to get the value of the field when changed.

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