Title: Select Dropdown Option Based on Characters
Last modified: January 22, 2022

---

# Select Dropdown Option Based on Characters

 *  Resolved [sonny123](https://wordpress.org/support/users/sonny123/)
 * (@sonny123)
 * [4 years, 4 months ago](https://wordpress.org/support/topic/select-dropdown-option-based-on-characters/)
 * Hi,
 * I have a dropdown field, fieldname9, with text-value pairs like a-300, b-200,
   and c-100, and I want to do something based on whether certain characters are
   present in an option or the vt/text.
 * I’ve tried:
 * * if (fieldname9.options[fieldname9.selectedIndex].text.indexOf(“a”) == -1) do
   something;
 * * if (fieldname9.text.indexOf(“a”) != -1) do something;
 * * if (fieldname9.vt.indexOf(“a”) != -1) do something;
 * * if (fieldname9.value.indexOf(“3”) != -1) do something;
 * But all of them break the function, and I’ve tested to see if it wasn’t the do
   something that was the problem.

Viewing 2 replies - 1 through 2 (of 2 total)

 *  Plugin Author [codepeople](https://wordpress.org/support/users/codepeople/)
 * (@codepeople)
 * [4 years, 4 months ago](https://wordpress.org/support/topic/select-dropdown-option-based-on-characters/#post-15279115)
 * Hello [@sonny123](https://wordpress.org/support/users/sonny123/),
 * Thank you so much for using our plugin.
 * The process is simpler. The `|v` modifier in the field’s name gives you access
   to the `vt` attribute in the option selected. So, the code would be:
 * `if(fieldname9|v.indexOf('a') != -1) do something;`
 * or using regular expression:
 * `if(/a/i.test(fieldname9|v)) do something;`
 * Best regards.
 *  Thread Starter [sonny123](https://wordpress.org/support/users/sonny123/)
 * (@sonny123)
 * [4 years, 4 months ago](https://wordpress.org/support/topic/select-dropdown-option-based-on-characters/#post-15279277)
 * That’s perfect, thank you!
 * Great plugin btw.

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Select Dropdown Option Based on Characters’ is closed to new replies.

 * ![](https://ps.w.org/calculated-fields-form/assets/icon-256x256.jpg?rev=1734377)
 * [Calculated Fields Form](https://wordpress.org/plugins/calculated-fields-form/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/calculated-fields-form/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/calculated-fields-form/)
 * [Active Topics](https://wordpress.org/support/plugin/calculated-fields-form/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/calculated-fields-form/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/calculated-fields-form/reviews/)

 * 2 replies
 * 2 participants
 * Last reply from: [sonny123](https://wordpress.org/support/users/sonny123/)
 * Last activity: [4 years, 4 months ago](https://wordpress.org/support/topic/select-dropdown-option-based-on-characters/#post-15279277)
 * Status: resolved