Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Javascript function confirm submit, not working

Posted on 2017-08-14
5
Medium Priority
?
34 Views
Last Modified: 2017-08-14
Hello all,

The following function is being called by a button ‘onclick’. However, it submit the ‘Form’ even if cancel is clicked!!!
What is the problem?

Kind regards

Abiel M de Groot

<button class="Part_SubmitBUTT" onclick="SubmitPArtesForm()">Are you sure you want to do this?</button>

-------------------------------------------------

function SubmitPArtesForm() {
  if(confirm("Are you sure you want to do this?"))
        document.getElementById("PartesPendingXX").submit();
  else
    return false;
}
0
Comment
Question by:Abiel de Groot
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 53

Expert Comment

by:Ryan Chong
ID: 42253500
quick try:

<button class="Part_SubmitBUTT" onclick="SubmitPArtesForm(this.form)">Are you sure you want to do this?</button>

Open in new window


function SubmitPArtesForm(frm) {
  if (confirm("Are you sure you want to do this?")) {
      frm.submit();
 }
} 

Open in new window

0
 
LVL 5

Author Comment

by:Abiel de Groot
ID: 42253503
It is still submitting even when I click cancel!

A
0
 
LVL 53

Accepted Solution

by:
Ryan Chong earned 2000 total points
ID: 42253507
try this:

<form action="test.here.asp" method="post">
    <button class="Part_SubmitBUTT" type="button" onclick="SubmitPArtesForm(this.form)">Are you sure you want to do this?</button>
</form>

<script type="text/javascript">
    function SubmitPArtesForm(frm) {
        if (confirm("Are you sure you want to do this?")) {
            frm.submit();
        }
    }

</script>
0
 
LVL 53

Expert Comment

by:Ryan Chong
ID: 42253508
or:

<form action="test.here.asp" method="post" onsubmit="return SubmitPArtesForm()">
    <button class="Part_SubmitBUTT" type="submit">Are you sure you want to do this?</button>
</form>

<script type="text/javascript">
    function SubmitPArtesForm() {
        return (confirm("Are you sure you want to do this?"));
    } 

</script>

Open in new window

0
 
LVL 5

Author Closing Comment

by:Abiel de Groot
ID: 42253561
Many thanks
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
A while back, I ran into a situation where I was trying to use the calculated columns feature in SharePoint 2013 to do some simple math using values in two lists. Between certain data types not being accessible, and also with trying to make a one to…
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…

704 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