Solved

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

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

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

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

Suggested Solutions

The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
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…

756 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