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 4 of 4
  1. #1
    New Coder
    Join Date
    Jun 2002
    Posts
    70
    Thanks
    0
    Thanked 0 Times in 0 Posts

    confirm() yes/no

    Hi. Does anyone have a JavaScript function that simulates confirm(), but uses [Yes][No] buttons?

  • #2
    Regular Coder
    Join Date
    Jun 2002
    Posts
    626
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Here is one that I put together for someone else:
    <html>
    <head>
    <title>Custom ConFirm, Alert and Prompt</title>
    <STYLE>
    /* You can modify these styles to anything you want (or is allowed). */
    /* These are used by both browsers. You can set these to your preferences. */
    .td1style {font-weight:bold;border:1px solid black;background-color:lightgrey;color:blue;font-size:14px;fontFamily:Verdana;}
    .td2style {font-weight:bold;border:1px solid black;background-color:lightyellow;font-size:12px;font-family:Verdana;}
    /* the style below is for the links that are inside the div when it pops up */
    .linkstyle {font-weight:bold;font-size:12px;text-decoration:none}
    </STYLE>
    <SCRIPT LANGUAGE="JavaScript">
    var msgtop=50 // Set the top position of the div
    var msgleft=20 // Set the left position of the div

    /* The following three variables are for setting the properties of your table contained within the div. */
    var tborder="0"
    var cspace="0"
    var cpad="0"
    var tabheight=50 // Set the height of table
    var tabwidth=150 // Set the width of table
    var td1height=10
    var td2height=30
    var boxt=""
    function Domsg(flag)
    {
    hidebox() // Hide the box after clicking on text link in box
    if(flag=="Yes")
    {
    msg="You Clicked "+flag+"!"
    }
    else
    {msg="Why did you click "+flag+"?"}
    document.formbx.result.value=msg
    }
    function DoFormbox(msgtext)
    {
    theString="<TABLE WIDTH='"+tabwidth+"' HEIGHT='"+tabheight+"' BORDER="+tborder+" CELLSPACING="+cspace+" CELLPADDING="+cpad+"><TR><TD HEIGHT='"+td1height+"' CLASS='td1style' ALIGN='left'><B>"
    theString+=""+msgtext+"</B></TD></TR><TR><TD HEIGHT='"+td2height+"' ALIGN='center' CLASS='td2style'><A HREF='javascriptomsg(\"Yes\")' class='linkstyle'>Yes</A>&nbsp &nbsp<A HREF='javascriptomsg(\"No\")' class='linkstyle'>No</A></TD></TR></TABLE>"
    if (document.layers) // Netscape 4.0+
    {
    document.formbox.document.write(theString)
    document.formbox.document.close()
    document.formbox.left=msgleft
    document.formbox.top=msgtop+40
    document.formbox.visibility="show"
    }
    else
    {
    if(document.getElementById) // Internet Explorer 5.0+ and Netscape 6.0+
    {
    elm=document.getElementById("formbox")
    elm.innerHTML=theString
    elm.style.top=msgtop
    elm.style.left=msgleft
    elm.style.visibility = "visible"
    }
    }
    }

    // This function is for hiding the div
    function hidebox()
    {
    if (document.layers) // Netscape 4.0+
    {
    document.formbox.visibility="hidden"
    }
    if(document.getElementById) // Netscape 6.0+ and Internet Explorer 5.0+
    {
    elm.style.visibility="hidden"
    }
    }
    </SCRIPT>
    </head>
    <body>
    <div id="formbox" style="position:absolute;visibility:hidden;left:0;top:0;"></div>
    <CENTER>
    <H1>Custom Confirm</H1>
    <form name="formbx">
    <input type="text" name="result" size="30">
    </form>
    <A HREF="javascriptoFormbox('Are you sure?')">Click Me for a Confirm Box</A><BR>
    </CENTER>
    </body>
    </html>

  • #3
    New to the CF scene
    Join Date
    Oct 2007
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Pop up

    This doesn't simulate the pop like confirm. Is there a way to do this like confirm only with 'Yes' and 'No' buttons?
    Last edited by Tuno; 10-05-2007 at 11:26 AM.

  • #4
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,302
    Thanks
    203
    Thanked 2,562 Times in 2,540 Posts
    If your question is "Is it possible to alter the 'OK' and 'Cancel' buttons in a Javascript confirm box to 'Yes' and 'No'?", the answer is No.


  •  

    Posting Permissions

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