SitePoint Sponsor

User Tag List

Results 1 to 2 of 2

Threaded View

  1. #1
    Gre aus'm Pott gold trophysilver trophybronze trophy
    Pullo's Avatar
    Join Date
    Jun 2007
    219 Post(s)
    13 Thread(s)

    How do I create a menu with optgroup labels? [SOLVED]


    I'm trying to produce a select menu with "optgroup" tags.
    The HTML output should look like this:
    HTML Code:
      <optgroup label="Europe">
        <option value="Denmark">Denmark</option>
        <option value="Germany">Germany</option>
        <option value="France">France</option>
      <optgroup label="North America">
        <option value="US">United States</option>
        <option value="Canada">Canada</option>
    In rails I'm typing this:
    <%= :member_1, 
    grouped_options_for_select ([['North America',
    [['United States','US'],'Canada']],
    ['Europe',['Denmark','Germany','France']]]) %>
    The result is that rails is adding the generated HTML to the select menu (see screen shot)

    Here is the HTML produced by Rails:
    HTML Code:
    <select id="applicant_member_1" name="applicant[member_1]">
    <option value="&lt;optgroup label=&quot;North America&quot;&gt;
    &lt;option value=&quot;US&quot;&gt;United States&lt;/option&gt;">
    &lt;optgroup label=&quot;North America&quot;&gt;&lt;
    option value=&quot;US&quot;&gt;United States&lt;/option&gt;

    Can anyone help me to sort this out?
    What am I doing wrong?
    How do I properly create a menu with optgroup labels?

    Thanks in advance for your help
    Attached Images Attached Images
    Last edited by Pullo; Apr 27, 2009 at 06:48.


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts