faqts : Computers : Programming : Languages : JavaScript : Language Core

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

386 of 569 people (68%) answered Yes
Recently 6 of 10 people (60%) answered Yes

Entry

How to write YESNO message box in javascript?

Jan 8th, 2003 18:39
Jean-Bernard Valentaten, Kulandaivadivel Duraisamy,


Unlike Java, C++, VisualBasic etc. JavaScript will not allow you to 
manipulate the widgets, so it is not possible to write a real YESNO 
message box using JavaScript only.
But there are workarounds and features that will let you get a decision 
by the user.
The first way is to use the confirm() method located in the window 
container:
function YESNOBox(msg)
{
  return confirm(msg);
}
The confirm method opens a panel displaying a string (called msg in the 
function above) and two buttons ("OK" and "Cancel"). If "OK" is clicked 
confirm() returns true else false.
If this doesn't suit you, you will have to write some html-code that 
shows the panel the way you want it to look and have some JavaScript 
return true or false depending on which button was clicked.
HTH,
Jean