[please help] I don't know how to validate this drop down menu

Discussion in 'HTML & Website Design' started by TransPersonal, Aug 21, 2009.

  1. #1
    Everything on my site passes through the w3 validation except for this drop down menu I'm using:

    <div id="dropDownMenu">
    <select id="drop_down" name="archive-dropdown"onchange='document.location.href=this.options[this.selectedIndex].value;'>
    <option value="">Check these out</option>
    <option value='http://mysite.com/something'> hi </option>
    <option value='http://mysite.com/something'> hello </option>
    <option value='http://mysite.com/something'> hi again </option>
    <option value='http://mysite.com/something'> hola </option>
    </select>
    </div>

    Can a kind soul please change this code around so it would validate? Some one already told me how to do it but whatever it was they said went right over my head!
     
    TransPersonal, Aug 21, 2009 IP
  2. AssistantX

    AssistantX Peon

    Messages:
    173
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    0
    #2
    The code you posted is (X)HTML valid (besides the lack of space between dropdown"onchange) as long as you code it as such:

    XHTML -
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
      <head>
        <title>Your Page</title>
      </head>
      <body>
        <div id="dropDownMenu">
          <select id="drop_down" name="archive-dropdown" onchange='document.location.href=this.options[this.selectedIndex].value;'>
             <option value="">Check these out</option>
             <option value='http://mysite.com/something'> hi </option>
             <option value='http://mysite.com/something'> hello </option>
             <option value='http://mysite.com/something'> hi again </option>
             <option value='http://mysite.com/something'> hola </option>
           </select>
        </div>
      </body>
    </html>
    
    HTML:
    or HTML:
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
    <html lang="en">
      <head>
        <title>Your Page</title>
      </head>
      <body>
        <div id="dropDownMenu">
          <select id="drop_down" name="archive-dropdown" onchange='document.location.href=this.options[this.selectedIndex].value;'>
             <option value="">Check these out</option>
             <option value='http://mysite.com/something'> hi </option>
             <option value='http://mysite.com/something'> hello </option>
             <option value='http://mysite.com/something'> hi again </option>
             <option value='http://mysite.com/something'> hola </option>
           </select>
        </div>
      </body>
    </html>
    
    HTML:
    In both examples, I simply added a doctype and required [X]HTML tags: <body>, <html>, <title>, and <head>.
     
    AssistantX, Aug 21, 2009 IP
  3. TransPersonal

    TransPersonal Peon

    Messages:
    48
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thanks a lot AssistantX!

    The code I posted was the HTML result of my PHP code. For whatever reason I just changed this PHP:

    <option value=""><?php echo attribute_escape(__('Check these out')); ?></option>

    to static HTML:

    <option value="">Check these out</option>

    in my PHP file and now it validates. Weird...:p
     
    TransPersonal, Aug 21, 2009 IP
  4. AssistantX

    AssistantX Peon

    Messages:
    173
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    0
    #4
    I'm not 100% familiar with Wordpress, but according to the documentation, it seems as though that should simply print "Check these out" (without quotes) in HTML and not cause any validation errors. What did the errors you received say?
     
    AssistantX, Aug 21, 2009 IP