Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Javascript function confirm submit, not working

Posted on 2017-08-14
5
Medium Priority
?
51 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
  • 3
  • 2
5 Comments
 
LVL 54

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 54

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 54

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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
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…
Suggested Courses

782 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