locked
Sharepoint 2007: Document Library capture event click on Ok button using javascript RRS feed

  • Question

  • I need your help guys!

    I am customizing something on document library using content editor web part. Just want to ask how can I capture the event click on Ok button. For example I will fire an alert when Ok button has been clicked?

    How to do this in javascript?

     

    Thanks!

    Thursday, December 22, 2011 7:48 AM

Answers

  • Hi,

    You can achieve this via JavaScript and JQuery.

    <script type="text/javascript">

    var OKbutton=document.getElementById("id");

    OKbutton.onclick = (function (e){

          alert("1");  //your operations.

    });

    </script>

    The method above will overwrite the onclick function, so the self-contained onclick function will not work.

     

    <script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.7.1.min.js" type="text/javascript"></script>

    <script type="text/javascript">

         $(document).ready(function(){

                $('#id').click(function() {

                       alert("1");  //your operations.

               });

     

    });

    </script>

    This method can reserve the previous onclick function. When you click OK button, it will execute the function above, then execute the self-contained onclick function.

    You can choose the one you need of the two methods.

    Thanks.


    Emir Liu

    TechNet Community Support

    • Marked as answer by Emir Liu Thursday, December 29, 2011 9:01 AM
    Thursday, December 22, 2011 9:33 AM

All replies

  • Hi,

    You can achieve this via JavaScript and JQuery.

    <script type="text/javascript">

    var OKbutton=document.getElementById("id");

    OKbutton.onclick = (function (e){

          alert("1");  //your operations.

    });

    </script>

    The method above will overwrite the onclick function, so the self-contained onclick function will not work.

     

    <script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.7.1.min.js" type="text/javascript"></script>

    <script type="text/javascript">

         $(document).ready(function(){

                $('#id').click(function() {

                       alert("1");  //your operations.

               });

     

    });

    </script>

    This method can reserve the previous onclick function. When you click OK button, it will execute the function above, then execute the self-contained onclick function.

    You can choose the one you need of the two methods.

    Thanks.


    Emir Liu

    TechNet Community Support

    • Marked as answer by Emir Liu Thursday, December 29, 2011 9:01 AM
    Thursday, December 22, 2011 9:33 AM
  • Hi check the below code 

    <script type="text/javascript">

    function functionClick()

    {

    alert("Clicked OK button");

    }

     

    </script>

    <input type='text' id='clickme' onclick="functionClick();"/>


     
    • Proposed as answer by Geetanjali Arora Thursday, December 22, 2011 7:13 PM
    • Marked as answer by Steven AndrewsEditor Wednesday, December 28, 2011 5:30 PM
    • Unmarked as answer by Mike Walsh FIN Wednesday, December 28, 2011 5:40 PM
    • Unproposed as answer by Mike Walsh FIN Wednesday, December 28, 2011 5:40 PM
    • Edited by Mike Walsh FIN Wednesday, December 28, 2011 5:41 PM should not be rewarded for doing so
    Thursday, December 22, 2011 6:47 PM