Link to home
Start Free TrialLog in
Avatar of Yvonne Todd-Ofreneo
Yvonne Todd-Ofreneo

asked on

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.
Avatar of Prakash Samariya
Prakash Samariya
Flag of India image

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();
      }
});
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.
Avatar of Yvonne Todd-Ofreneo
Yvonne Todd-Ofreneo

ASKER

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
          }
ASKER CERTIFIED SOLUTION
Avatar of Prakash Samariya
Prakash Samariya
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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.