Solved

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

Posted on 2010-09-09
5
748 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

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

Suggested Solutions

Avoid defining the variables in the global scope; trying to define them in a local function scope. Because:   • Look-up is performed every time a variable is accessed.   • Variables are resolved backwards from most specific to least specific scope…
Article by: DanRollins
This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7850-Hex-Maze-Part-2.html), we'll extend the program by adding a depth-…
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…

867 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

21 Experts available now in Live!

Get 1:1 Help Now