none
PreSaveAction is not firing

    Question

  • I have a custom edit form for my list to which I have added the following code under "PlaceHolderMain". PreSaveAction does not seem to fire as I don't see the alerts upon clicking Save. Thanks for the help.

    <asp:Content ContentPlaceHolderId="PlaceHolderMain" runat="server">
    <script type="text/javascript">
     var $j = jQuery.noConflict();
     $j(document).ready(function() {
      function PreSaveAction() {
       alert("here");
       var txtStatus = $j(":input[title='Status']").val();
       if(txtStatus == "In Progress"){       
       alert("Invalid Status");       
       var statusfocus = $j(":input[title='Status']");       
       statusfocus .focus();       
       return false;}
       return true;
      }

    });

    </script>



    • Edited by vmrao Tuesday, October 11, 2011 6:24 PM
    Tuesday, October 11, 2011 6:23 PM

Answers

All replies

  • Hi vmrao,

    You have only declared the function. You need to call the function also. I would do it the following way:

     

    <script type="text/javascript">
     var $j = jQuery.noConflict(); 
     $j(document).ready(function() {
         
           PreSaveAction();
    
    });
    
     function PreSaveAction() { 
       alert("here");
       var txtStatus = $j(":input[title='Status']").val(); 
       if(txtStatus == "In Progress"){        
       alert("Invalid Status");        
       var statusfocus = $j(":input[title='Status']");        
       statusfocus .focus();        
       return false;}
       return true;
      }
    
    </script>
    


     


    Tuesday, October 11, 2011 7:26 PM
  • I though PreSaveAction is a SP default function and need not be called as it is called by PreSaveItem automatically when clicked on Save button. Can someone please clarify this.
    Tuesday, October 11, 2011 8:46 PM
  • Did the above code work?

    also, try it without the  $j(document).ready()

     

    <script type="text/javascript">
     var $j = jQuery.noConflict(); 
     function PreSaveAction() { 
       alert("here");
       var txtStatus = $j(":input[title='Status']").val(); 
       if(txtStatus == "In Progress"){        
       alert("Invalid Status");        
       var statusfocus = $j(":input[title='Status']");        
       statusfocus .focus();        
       return false;}
       return true;
      }
    
    </script>

    Also, checkout this link on the PreSaveAction() function:

    http://ghamson.wordpress.com/2011/01/25/useful-javascript-function-presaveaction-sp2010-sharepoint-ps2010-projectserver-in/

    • Edited by Vardhaman Deshpande Tuesday, October 11, 2011 8:57 PM
    • Marked as answer by vmrao Wednesday, October 12, 2011 8:17 PM
    Tuesday, October 11, 2011 8:56 PM
  • Deleting document.ready did the trick. Thanks.

    Wednesday, October 12, 2011 8:16 PM