Solved

Message box having Yes and No Buttons instead of Ok and Cancel buttons

Posted on 2004-10-26
10,552 Views
Last Modified: 2012-08-13
Hi
I would like to know whether we can have a message box with Yes and No Buttons in Javascript. I am aware of the confirm message box having OK and Cancel Buttons, but my requirements is for a message box with Yes and No buttons. I am aware that we can define the number of boxes in a message box using VBScript, but i have to give the same functionality using Javascript. Please help asap.

Regards

Prashant
0
Question by:pvasha
    4 Comments
     
    LVL 33

    Accepted Solution

    by:
    You can have the confirm box (as you already know) .The other alternative might be calling a modal
    window ( that you create ) and use it.Other alternative being vbscript
    0
     
    LVL 33

    Assisted Solution

    by:sajuks
    //Check this, a code posted by another expert in this forum
    <script language="JavaScript">
         function alertBox(alertMessage,height,width)
              {
              // This stuff centers the window
              windowWidth = (width == null) ? 200 : width; // width of the new window
             windowHeight = (height == null) ? 30 : height; // height of the new window
             windowLeft = (screen.width / 2) - (windowWidth / 2); // center the window right to left
             windowTop = (screen.height / 2) - (windowHeight / 2); // center the window top to bottom
             
              // the values get inserted into the features parameter of the window.open command...
              var windowLocation = "top=" + windowTop + ",left=" + windowLeft + ",height=" + windowHeight + ",width=" + windowWidth;
              alertWindow = window.open("","alertWindow",windowLocation);
              alertWindow.document.write("<html><head><title>Alert!</title></head><body bgcolor='#C0C0C0'>");
              alertWindow.document.write("<div align='center'>" + alertMessage + "<br>");
              alertWindow.document.write("<form><input type='button' value=' YES ' onclick='window.close()' align='center'></form>");
              alertWindow.document.write("</div></body></html>");
              }
    </script>


    // Here is the call:
    <input type="button" value="test" onclick="alertBox('This is an alert!!!')">
    0
     
    LVL 3

    Assisted Solution

    by:andYetAnotherLoginName
    change
             alertWindow.document.write("<html><head><title>Alert!</title></head><body bgcolor='#C0C0C0'>");

    to
             alertWindow.document.write("<html><head><title>Alert!</title></head><body bgcolor='buttonface' style='border:0px none'>");

    for better appearence.
    0
     
    LVL 5

    Assisted Solution

    by:mrielf
    0

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    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

    Avoid defining the variables in the global scope; trying to define them in a local function scope. Because:   • Look-up is performed every time a variable is accessed.   • Variables are resolved backwards from most specific to least specific scope…
    This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
    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…

    910 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

    14 Experts available now in Live!

    Get 1:1 Help Now