views:

373

answers:

1

I'm trying to hide a form label and textbox, by default, and make them appear when an option is selected. I can't see why my code keeps failing.

<tr>
   <td><label>My Label</label></td>
   <td>
      <select name="1" id="1">
         <option value="2" selected="selected">2</option>
         <option value="3">3</option>
         <option value="4">4</option>

         <option value="Other">Other</option>
       </select>
   </td>
   <td><label class=".otherHide">Other</label></td>
   <td><input class=".otherHide" type="text" name="otherSpec" id="otherSpec" /></td>
</tr>

jQuery(document).ready(function()
{
   jQuery('#1').change(function()
   {
      jQuery('#1 option:selected').each(function()
      {
         if (jQuery(this).text() == 'Other')
         {
            jQuery('.otherHide').each(function()
            {
               jQuery(this).animate({opacity: 0.0}, 2000);
            });
         }
      });
   }).change();
});

It's currently set to hide the form elements why I was testing.

I originally wasn't using classes and tried my hand at traversing through it. Failing at that, I resorted to classes and ended up failing.

Why isn't jQuery selecting my elements? >.<

+1  A: 

It's worth noting from the HTML 4.01 specification:

ID and NAME tokens must begin with a letter ([A-Za-z]) and may be followed by any number of letters, digits ([0-9]), hyphens ("-"), underscores ("_"), colons (":"), and periods (".").

Other than that, there is no element with class otherHide in your HTML.

cletus
The id's aren't actually numbers. I just used them to try prevent people focusing on irrelevant information. In hindsight, bad idea xDI also seem to have pasted old code >_>The two last TD's should read: <td><label class=".otherHide">Other</label></td> <td><input class=".otherHide" type="text" name="otherSpec" id="otherSpec" /></td>
Kane
you want class="otherHide" rather than class=".otherHide". The period is only used in the CSS selector to indicate you're looking for a class.
Gareth
...half an hour staring at this code trying to figure out why jQuery wasn't playing nicely and it turns out to be such a simple mistake in the HTML >_>Thanks for the help ;)
Kane