How do I hide/show fields based on a selection from a drop-down menu using jQuery?

I have been tryign to find code using google to figure this out but there seem to be no good examples of how to accomplish this. I have a form built in SharePoint that I would like to display certain fields based on a selection from a drop down menu. If someone could point me in the right direction it would be greatly appreciated.
Yvonne Todd-OfreneoAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Prakash SamariyaIT ProfessionalCommented:
Please try like this jQuery sample  
$("select").change(function(){
      if($(this).attr("value")=="show"){
            $("input[type=textbox]").show();
      }else if($(this).attr("value")=="hide"){
            $("input[type=textbox]").hide();
      }
});
0
Mandeep SinghDatabase AdministratorCommented:
Hi,

May it give you an idea, how to do this. It not for show/hide. It's for enable and disable of controls through javascript.

http://hightechnology.in/enable-disable-all-asp-net-controls-placed-inside-div-on-dropdownlist-selection/

In which you can replace disabled with hide.
0
Yvonne Todd-OfreneoAuthor Commented:
I tried using this code and I can't seem to get it to work. When I run the code on the Edit form nothing happens. Am I missing something?


       var field1;   //Directorate

       var selectedTypePur = $("select[title = 'Request Type']").val();
       if (selectedTypePur == "Other")
          {  
               field1 = GetControl("Directorate");
               field1.parentNode.parentNode.style.display="";      //show
          }
       
       else
          {  
               field1 = GetControl("Directorate");
               field1.parentNode.parentNode.style.display="none";      //hide
          }
0
Prakash SamariyaIT ProfessionalCommented:
What this function returns GetControl("Directorate");?

jQuery objects do not have a "parentNode" property. That is for working with DOM elements. You can use like below
control.get(0).parentNode.parentNode.parentNode.style.display="none";

OR if it returns jQuery object, use it like
control.parent().parent().parent().css('display', 'none');
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Yvonne Todd-OfreneoAuthor Commented:
If a selection is made from the "Request Type" field, in this case it is "Other" i want fields to be displayed like "Directorate". If another Selection like "Purchase order is chosen from "Request Type", i want to hide fields Like "Directorate" from view.

I will try the code you provided above in the morning to see if it works. Thank for letting my know i was using incorrect syntax.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
jQuery

From novice to tech pro — start learning today.