WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm using CF7 and I need to have a dropdown with a non selectable category "header" such as

US States






Albania etc....

With "US States" and "Countries" not an option to submit. Thanks http://wordpress.org/extend/plugins/contact-form-7/[1]

EDIT: I solved the problem myself if anyone has the same issue

I used JQuery and gave the options I wanted to make non-selectable an empty value.

$("option:nth-child(1), option:nth-child(1)").val("");
$("option:nth-child(1), option:nth-child(53)").val("");
share|improve this question

closed as off-topic by Johannes Pille, s_ha_dum Oct 6 '14 at 23:28

This question appears to be off-topic. The users who voted to close gave this specific reason:

If this question can be reworded to fit the rules in the help center, please edit the question.

up vote 0 down vote accepted

I can see how your solution works, but there is a semantic element created for exactly what you want: <optgroup>. Whatever your solution, I'd encourage you to use that instead.

Searching for "contact form 7 optgroup" you'll discover that other people are looking for the same thing you are and trying to implement <optgroup> to do it. Here's one answer that includes both a javascript solution and a plugin hack (probably not a good idea). Probably the better solution I've found is this one. It's a javascript to replace Contact Form 7 select options with the optgroup element using a specified syntax.

That final solution should probably remain stable even if CF7 adds optgroup support down the road.

share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.