Solved

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

Posted on 2010-09-09
5
745 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
Comment Utility
<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
Comment Utility
<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
Comment Utility
<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
Comment Utility
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
Comment Utility
Both ways work. Thank you,
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
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…

772 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

10 Experts available now in Live!

Get 1:1 Help Now