• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 3651
  • Last Modified:

JS alert & confirm

hi experts,
 have a this link :
<a href='index.php?delete=yes' onclick='disp_confirm()' value='Display a confirm box'><delete</a>

<script type="text/javascript">
function disp_confirm() {
  var r=confirm("Press a button")
  if (r==true)  {go ahead with the link  : 'index.php?delete=yes' }
  else { stay where you are  }
  }
</script>

regards,
0
uk1900
Asked:
uk1900
  • 3
  • 2
2 Solutions
 
BraveBrainCommented:
<a href='index.php?delete=yes' onclick='return confirm('Are you sure?')' title='Display a confirm box'>&lt;delete</a>

<script type="text/javascript">
// no function needed
</script>

0
 
gops1Commented:
Try this way:

<html>
      <head>
            <head>
                  <title>Script Demo Gops</title>
                  <script language="javascript">
                        function disp_confirm() {
                              return confirm("Press a button")
                        }
                  </script>
            </head>
<body>
<a href='index.php?delete=yes' onclick='return disp_confirm()' value='Display a confirm box'>delete</a>
</body>
</html>
0
 
gops1Commented:
Brave's suggestion is better
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
BraveBrainCommented:
Thanks gops.
@ uk1900: Which one you prefer depends on whether or not you want to keep a custom function or not. With mine you have to enter the confirm message within the onclick or set a global var to use, i.e. return confirm(myVar), while gops1 makes use of your current function.

Note that there's no attribute VALUE for the A tag. You probably wanted TITLE. Also, the < in front of link text 'delete' should be &lt; since it's not a part of a tag.
0
 
uk1900Author Commented:
hi BraveBrain and gops1
I think I will use this one :

<a href='index?del=1' onclick="return confirm('Are you sure?')">delete</a>

thank you for your help.
0
 
BraveBrainCommented:
Glad to help. Thanks for the grade and points.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now