Solved

Javascript help

Posted on 2011-09-06
3
188 Views
Last Modified: 2012-05-12
Hi

I have a following function which is executed when a user clicks a button. However, I would like to send an a warning before the function, where I would like to give a message, "Do you want to update the item?" and when user says, 'Yes', then only i want the function to update. Can anyone help me how to achive this using following script below?





function PMapprove(id, value) {

      var pmmsg = "<?xml version='1.0' encoding='utf-8'?> \
            <soap:Envelope xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:soap='http://www.w3.org/2003/05/soap-envelope'> \
                  <soap:Body> \
                        <UpdateListItems xmlns='http://schemas.microsoft.com/sharepoint/soap/'> \
                              <listName>AESO Reports Library</listName> \
                                    <updates> \
                                          <Batch OnError='Continue'> \
                                                <Method ID='1' Cmd='Update'> \
                                                      <Field Name='Ready_x0020_for_x0020_Review'>" + value +  "</Field> \
                                                      <Field Name='ID'>" + id + "</Field> \
                                                </Method> \
                                          </Batch> \
                                    </updates> \
                        </UpdateListItems> \
                  </soap:Body> \
            </soap:Envelope>";

      $.ajax({
            url: "myURL/_vti_bin/lists.asmx",
            asynch: false,
            beforeSend: function (xhr) {
                  xhr.setRequestHeader("SOAPAction",
                  "http://schemas.microsoft.com/sharepoint/soap/UpdateListItems");
            },
            type: "POST",
            dataType: "xml",
            data: pmmsg,
            contentType: "text/xml; charset=\"utf-8\""
      });
      
}
0
Comment
Question by:Techsavy
3 Comments
 
LVL 40

Accepted Solution

by:
gurvinder372 earned 250 total points
ID: 36493600
just call this function

function warn(id, value)
{
   if (confirm("Do you want to update the item?") )
   {
      PMapprove(id, value);
   }
}
0
 
LVL 17

Expert Comment

by:sonawanekiran
ID: 36493628
OR use below function
function PMapprove(id, value) {
 if (confirm("Do you want to update the item?") )
   {
      var pmmsg = "<?xml version='1.0' encoding='utf-8'?> \
            <soap:Envelope xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:soap='http://www.w3.org/2003/05/soap-envelope'> \
                  <soap:Body> \
                        <UpdateListItems xmlns='http://schemas.microsoft.com/sharepoint/soap/'> \
                              <listName>AESO Reports Library</listName> \
                                    <updates> \
                                          <Batch OnError='Continue'> \
                                                <Method ID='1' Cmd='Update'> \
                                                      <Field Name='Ready_x0020_for_x0020_Review'>" + value +  "</Field> \
                                                      <Field Name='ID'>" + id + "</Field> \
                                                </Method> \
                                          </Batch> \
                                    </updates> \
                        </UpdateListItems> \
                  </soap:Body> \
            </soap:Envelope>";

      $.ajax({
            url: "myURL/_vti_bin/lists.asmx",
            asynch: false,
            beforeSend: function (xhr) {
                  xhr.setRequestHeader("SOAPAction",
                  "http://schemas.microsoft.com/sharepoint/soap/UpdateListItems");
            },
            type: "POST",
            dataType: "xml",
            data: pmmsg,
            contentType: "text/xml; charset=\"utf-8\""
      });
   }   
}

Open in new window

0
 
LVL 7

Assisted Solution

by:Kishan Zunjare
Kishan Zunjare earned 250 total points
ID: 36494423
Hi,

You can go for this;
<script type="text/javascript">
function show_confirm()
{
var r=confirm(""Do you want to update the item?" ");
if (r==true)
  {
          // Your JS Code
  }
else
  {
  alert("You pressed Cancel!");
  }
}
</script>
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article, we'll look how to sort an Array in JavaScript, including the more advanced techniques of sorting a collection of records either ascending or descending on two or more fields. Basic Sorting of Arrays First, let's look at the …
In my daily work (mainly using ASP.net), I need to write a lot of JavaScript code. One of the most repetitive tasks I do are the jQuery Ajax calls. You know: (CODE) I don't know if for you it's the same, but for me is soooo tedious to write the …
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

932 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now