Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

How do I use "Cancel and Ok" function in Javascript?

Posted on 2007-10-08
11
Medium Priority
?
1,014 Views
Last Modified: 2008-01-09
Hello.
I want to add cancel button on javascript alert message.
How do I do that?

This is my coding so far:

Function button {
alert ("Are you sure?");
}

Thank you
0
Comment
Question by:erin027
  • 3
  • 3
  • 2
  • +3
11 Comments
 
LVL 14

Assisted Solution

by:Jai S
Jai S earned 100 total points
ID: 20038859
<script language="Javascript">

<!--
confirm ("This is a Javascript Confirm")
//-->

</script>
0
 
LVL 39

Assisted Solution

by:Pratima Pharande
Pratima Pharande earned 100 total points
ID: 20038879
Function button {
if (confirm ("Are you sure?"))
{
      return true;
}
else
{
 return false;

}

}
0
 
LVL 17

Assisted Solution

by:NicksonKoh
NicksonKoh earned 100 total points
ID: 20038895
Hi erin027,

confirm function returns true and false as shown in the below function.

function button() {
  answer = confirm("Are you sure?");
  if (answer) {
    alert ("You click OK.");
  }  else {
    alert ("You click Cancel.");
  }
}

Cheers,
NicksonKoh
0
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!

 
LVL 14

Expert Comment

by:Jai S
ID: 20038907
i dont understand why the same answers are being given again and again...its just waste of time...
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 20038947
@jaiganeshsrinivasan Actually, your comment did not actually DO anything with the confirm. and if you notice the times, they are given within 10 minutes...
0
 
LVL 17

Expert Comment

by:NicksonKoh
ID: 20038962
My apologies, I didn't see pratima_mcs's answer but jaiganeshsrinivasan, your answer doesn't seem to explain very clearly which is why I posted a clearer example.
0
 
LVL 14

Expert Comment

by:Jai S
ID: 20038964
its just a guidance to the author to point to the function...and not posting the same messages again and again...its obvious
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 20038974
Obvious to you but likely not to the poster
0
 
LVL 20

Expert Comment

by:informaniac
ID: 20040415
Please give the points to the concerned persons.....
0
 

Author Comment

by:erin027
ID: 20042121
Thank you guys.
I have one more question though.
How do I post send the info when user click 'Ok'?

<script language="javascript" type="text/javascript">
function button() {
      if (confirm ("Delete?")){
action="category_delete.asp?CategoryID=<%=rs("CategoryID")%>&CategoryImage=<%=rs("CategoryImage")%>";
            return;
            }
      else {
             return false;
            }
}
</script>
0
 
LVL 75

Accepted Solution

by:
Michel Plungjan earned 200 total points
ID: 20042710
either


<script language="javascript" type="text/javascript">
function button() {
      if (confirm ("Delete?"))
   location = "category_delete.asp?CategoryID=<%=rs("CategoryID")%>&CategoryImage=<%=rs("CategoryImage")%>";
}
</script>

or perhaps

<form action="category_delete.asp?CategoryID=<%=rs("CategoryID")%>&CategoryImage=<%=rs("CategoryImage")%>"
onSubmit="return confirm ('Delete?')">
<input type="submit">
</form>

watch the quotes
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
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…
Suggested Courses

810 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