Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    New Coder
    Join Date
    Nov 2007
    Posts
    36
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Javascript alert with Yes No buttons

    Hi,

    I want to show an alert box With Yes No Button..
    Like:
    You want to proceed

    Yes No


    Alert gives just OK, and confirm gives Ok and Cancel buttons

    Kindly tell me how can i get Yes And No buttons there.

    It is urgent please....

    Thanx,

    Ali

  • #2
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,641
    Thanks
    0
    Thanked 649 Times in 639 Posts
    You will have to build your own in page dialog using HTML. See http://javascript.about.com/library/blmodald1.htm for how to create a basic one with one button. Changing the HTML to add a second button and the JavaScript to test which button was pressed is a trivial change.
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

  • #3
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,029
    Thanks
    203
    Thanked 2,539 Times in 2,517 Posts
    <p> Do you want to proceed?" </p>
    <input type = "button" id = "ybutton" value = "Yes" onclick = "buttonwhich('You pressed YES')">
    <input type = "button" id = "nbutton" value = "No" onclick = "buttonwhich('You pressed NO')">
    <input type ="text" id = "answerbox">

    <script type = "text/javascript">
    function buttonwhich(message) {
    document.getElementById("answerbox").value = message;
    }
    </script>
    Last edited by Philip M; 12-11-2007 at 08:31 AM.

  • #4
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Location
    Urbana
    Posts
    4,350
    Thanks
    11
    Thanked 589 Times in 570 Posts
    for an easier to code synchronous solution,

    showModalDialog works in ie and in firefox3
    my site (updated 13/9/26)
    BROWSER STATS [% share] (2014/5/28) IE7:0.1, IE8:5.3, IE11:8.4, IE9:3.2, IE10:3.2, FF:18.2, CH:46, SF:7.9, NON-MOUSE:32%

  • #5
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,641
    Thanks
    0
    Thanked 649 Times in 639 Posts
    Quote Originally Posted by rnd me View Post
    for an easier to code synchronous solution,

    showModalDialog works in ie and in firefox3
    Why use a solution that is proprietary to only one or two browsers rahter than one that should work in thousands of different browsers.
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

  • #6
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Location
    Urbana
    Posts
    4,350
    Thanks
    11
    Thanked 589 Times in 570 Posts
    Quote Originally Posted by felgall View Post
    Why use a solution that is proprietary to only one or two browsers rahter than one that should work in thousands of different browsers.
    firefox 3 will quickly replace firefox2 when it comes out.

    combined with ie, "proprietary to only one or two browsers" will comprise 90&#37; of users. I try to worry more about the majorty than catering to and smaller interests. I have a hard time philosophically justififng limiting myself to pick up a few more people, who have other options available. Firefox is free and works on about any OS. If someone was dying to use my script, they could download firefox.


    my major interest in using showmodal is the simplicity of coding.

    compare the programming overhead of x=prompt("enter a value"), to
    somethings using an HTML replacement. You need to define callbacks, validate the input, clean up the modified DOM after, and so forth. What showmodal does with about 20 chars worth of instruction, would take hundreds of chars with HTML.

    As a compromise, show modal displays HTML. you could add your form right now for the "big two.5" browsers, and add the events and interaction code necessary to support that last 5-7%.


    as a bit of retort, who is using the "thousands of different browsers" you mention?

    I'll insert my 'snappy answer' to standards nazis here:
    "what kind of standard is used by only 7% of the market?"




    ---------

    as Spock says: "It's logical, the needs of the many outweigh the needs of the few.".
    Last edited by rnd me; 12-12-2007 at 03:09 AM.
    my site (updated 13/9/26)
    BROWSER STATS [% share] (2014/5/28) IE7:0.1, IE8:5.3, IE11:8.4, IE9:3.2, IE10:3.2, FF:18.2, CH:46, SF:7.9, NON-MOUSE:32%

  • #7
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,029
    Thanks
    203
    Thanked 2,539 Times in 2,517 Posts
    Quote Originally Posted by rnd me View Post
    I'll insert my 'snappy answer' to standards nazis here:
    "what kind of standard is used by only 7% of the market?"

    "The nice thing about standards is that there are so many to choose from."


  •  

    LinkBacks (?)


    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •