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.
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.
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.
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.parentNo de.style.d isplay=""; //show
}
else
{
field1 = GetControl("Directorate");
field1.parentNode.parentNo de.style.d isplay="no ne"; //hide
}
var field1; //Directorate
var selectedTypePur = $("select[title = 'Request Type']").val();
if (selectedTypePur == "Other")
{
field1 = GetControl("Directorate");
field1.parentNode.parentNo
}
else
{
field1 = GetControl("Directorate");
field1.parentNode.parentNo
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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.
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.
$("select").change(functio
if($(this).attr("value")==
$("input[type=textbox]").s
}else if($(this).attr("value")==
$("input[type=textbox]").h
}
});