Friday, October 22, 2010

Show/Hide free form text field on dropdown choice : Specify your own value


<script type="text/javascript" src="http://YourServer/development/jQuery/jquery-1.4.2.min.js"></script>
<script type="text/javascript">

$(document).ready(function() {

 //will  hide as the default selected column value is other than "Other" .
   var TitleSpan = $("span[Title='ColumnInternalName: Specify your own value:']").closest("tr").hide();
   var TitleInput = $("input[Title='ColumnInternalName : Specify your own value:']").closest("tr").hide();

//on dropdown choice change, we can show or hide the "specify your own value"
   $("select[title$=Column Name: Choice Drop Down']").change(function()
   {
     var selectedItem = $("#ctl00_m_g_XXXXXX_ctl00_DropDownChoice :selected").text();
     if(selectedItem == "Other")
      {
          var TitleSpan = $("span[Title='Column Name: Specify your own value:']").closest("tr").show();
          var TitleInput = $("input[Title='Column Name : Specify your own value:']").closest("tr").show();
      }
      else
      {
          var TitleSpan = $("span[Title=Column Name: Specify your own value:']").closest("tr").hide();
          var TitleInput = $("input[Title=Column Name : Specify your own value:']").closest("tr").hide();
      }
    });
 
 
});

</script>