locked
Enable and Disable and clear textarea box based on Dropdown selection RRS feed

  • Question

  • Hello All,

    I'm trying to Enable a multi-line textbox and disable and clear the multi-line text box based on the selection of Pending. If the selection is anything else, I want the multi-line text box to be enabled. I'm trying to do this using JQuery in SharePoint 2013. The code I have so far is listed below. However the alert isn't getting any value back at all.

    $(document).ready(function(){

    var text = $("#id_of_Dropdown").val();

    alert(text);

    if(text == "Pending")

    {

          $("input[value$='Save Changes']").attr('disabled',true);

          $("textarea[title$=PM Comments']").attr('disabled',true);

    }

    else

          

    {

    $("input[value$='Save Changes']").attr('disabled',false); $("textarea[title$=PM Comments']").attr('disabled',false);

    }

    })



    SharePoint Engineer - Mike

    Friday, July 7, 2017 8:11 PM

All replies

  • Hi Mike,

    Here is the link for you

    https://stackoverflow.com/questions/16569260/enable-disable-form-elements-based-on-dropdown-list


    Please remember to click Mark as Answer on the answer if it helps you

    Friday, July 7, 2017 8:54 PM
  • Hi,

    var text = $("#id_of_Dropdown").val(); will give the selected value of Dropdown, instead use

    $('#id_of_Dropdown:selected').text();

    Good luck

    Saturday, July 8, 2017 12:38 AM
  • Hi Mike,

    Please make sure the Jquery selector for drop down list is valid, a better way to select the drop down list is using the dropdown list title like below (as the dropdown id could have special character which not valid in Jquery):

    <script type="text/javascript" src="https://code.jquery.com/jquery-1.11.0.min.js"></script>
    <script type="text/javascript">
    $(document).ready(
    
    function () {
    var test =$("select[title='test']").val();
    
    console.log(test);
    
    if(test=="test1")
    {
      $("input[title='Title']").attr('disabled',true);
    }
    
    });
    
    </script>
    

    Thanks

    Best Regards


    Please remember to mark the replies as answers if they help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com

    Monday, July 10, 2017 7:32 AM
  • Hi Mike,

    I understand you want to disable the text area based upon the Status drop down. You want to disable the text area only when the Status is Pending. Below is the code which you are looking for:

    $("select[title='Status']").change(function () {
       if( $("select[title='Status']").val() = "Pending"){
        $("textarea[title='Comments']").attr("disabled", true);
       }
       else{
         $("textarea[title='Comments']").attr("disabled", false);
       }
    }); 

    Screenshot for reference:

    Hope this helps you!


    Please click the "Mark as Answer" button if this post solves your problem or "Vote As helpful if it was helpful! :)
    Explore the SharePoint

    Monday, July 10, 2017 3:17 PM
  • Hi Mike,

    How is everything going ? If my reply is helpful to this question, please mark it as answer so that it could help others who stuck with the same issue in the forum.

    Thanks

    Best Regards


    Please remember to mark the replies as answers if they help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com

    Thursday, July 13, 2017 7:18 AM