Solved

Javascript, Upon submit, ask to confirm "Yes" or "No", if Yes the proceed.

Posted on 2010-09-09
5
753 Views
Last Modified: 2012-05-10
Assume
<INPUT TYPE="submit" NAME="deleteOldEntries" VALUE="Delete all">
<input type=text name="mydate">

If submit button is press, show a popup to confirm deletion.  In message, display value from "mydate" text field.  If select yes, then proceed with the submit, otherwise, do nothing.
0
Comment
Question by:rgbcof
5 Comments
 
LVL 20

Expert Comment

by:chaitu chaitu
ID: 33634864
<script>
  function ex()
  {
 var r=confirm("Press a button"+document.getElementById("mydate").value);
if (r==true)
  {
  alert("You pressed OK!");
  }
else
  {
  alert("You pressed Cancel!");
  }

  }
  </script>

 </HEAD>

 <BODY>
  <INPUT TYPE="button" NAME="deleteOldEntries" VALUE="Delete all" onclick='ex()'>
<input type=text id="mydate" value='12-12-2008'>
If submit button is press, show a popup to confirm deletion.  In message, display value from "mydate" text field.  If select yes, then proceed with the submit, otherwise, do nothing.

 </BODY>
</HTML>
0
 
LVL 40

Expert Comment

by:gurvinder372
ID: 33634873
<INPUT TYPE="button" NAME="deleteOldEntries" VALUE="Delete all" onclick="submitForm()">

function submitForm()
{
    if (confirm("Do you really want to delete it?") )
    {
        document.forms[0].submit();
    }
}
0
 
LVL 10

Accepted Solution

by:
bugada earned 63 total points
ID: 33635456
<html>
<head>
   <scrip type="text/javascript">
      function confirmSubmit(form) {
          return confirm("Are you sure to delete all "+form.mydate.value + "?");
      }
   </script>
...

<form name="theform" onSubmit="return conformSubmit(this)">
   <input type="submit" name="deleteOldEntries" value="Delete all">
   <input type=text name="mydate">
</form>

...
<html>
0
 
LVL 15

Assisted Solution

by:StealthyDev
StealthyDev earned 62 total points
ID: 33635655
Hi, try this:
<form name="frmname" onsubmit="return(confirm('Are you sure want to delete: ' + document.frmname.mydate.value + '?'));">
  <INPUT TYPE="submit" NAME="deleteOldEntries" VALUE="Delete all">
  <input type=text name="mydate">
</form>

Open in new window

0
 

Author Closing Comment

by:rgbcof
ID: 33641916
Both ways work. Thank you,
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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 …
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…

828 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