custom text on 'confirm' popup buttons

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • dzeeq

    custom text on 'confirm' popup buttons

    Hi,
    I wonder if it's possible to replace standard text on confirm-popup
    buttons from 'ok' and 'cancel' to some other captions.
    If not, is there a way to create quickly custom dialog, with only two
    buttons, returning 'true' or 'false'? Would I have to use forms to
    return value from my custom dialog?
    Thanx for any help.
  • Lasse Reichstein Nielsen

    #2
    Re: custom text on 'confirm' popup buttons

    dzeeq@wp.pl (dzeeq) writes:
    [color=blue]
    > I wonder if it's possible to replace standard text on confirm-popup
    > buttons from 'ok' and 'cancel' to some other captions.[/color]

    It isn't.
    [color=blue]
    > If not, is there a way to create quickly custom dialog, with only two
    > buttons, returning 'true' or 'false'? Would I have to use forms to
    > return value from my custom dialog?[/color]

    There are plenty, they just won't be modal (i.e., prevent you from
    using the page while being shown). That also means that you can't
    simply call it as a function that returns the user's choice. You will
    have to get the answer from the click event instead.

    The simplest is to have a <div> with two buttons, and show it when
    needed. Something like:
    ---
    <style type="text/css">
    #confirmBox {
    width:10em;
    height:5em;
    position:absolu te;
    z-index:1;
    visibility:hidd en;
    background:blue ;
    color:white;
    border:6px double white;
    text-align:center;
    }
    </style>
    <script type="text/javascript">
    var answerFunction;
    function myConfirm(text, button1,button2 ,answerFunc) {
    var box = document.getEle mentById("confi rmBox");
    box.getElements ByTagName("p")[0].firstChild.nod eValue = text;
    var button = box.getElements ByTagName("inpu t");
    button[0].value=button1;
    button[1].value=button2;
    answerFunction = answerFunc;
    box.style.visib ility="visible" ;
    }
    function answer(response ) {
    document.getEle mentById("confi rmBox").style.v isibility="hidd en";
    answerFunction( response);
    }
    </script>
    ...
    <div id="confirmBox" >
    <p>Continue?</p>
    <p><input type="button" onclick="answer (true)" value="Ok">
    <input type="button" onclick="answer (false)" value="Cancel"> </p>
    </div>


    <script type="text/javascript">
    function tester(button) {
    myConfirm("Say Aye or Nay!","Aye","Na y",
    function(answer ) {
    button.value="L ast answer was: "+(answer?"Aye" :"Nay");
    });
    }
    </script>
    <input type="button" value="Answer me!" onclick="tester (this)">
    ---

    /L
    --
    Lasse Reichstein Nielsen - lrn@hotpop.com
    DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html>
    'Faith without judgement merely degrades the spirit divine.'

    Comment

    • Michael Winter

      #3
      Re: custom text on 'confirm' popup buttons

      "dzeeq" wrote on 13/11/2003:
      [color=blue]
      > Hi,
      > I wonder if it's possible to replace standard text on confirm-popup
      > buttons from 'ok' and 'cancel' to some other captions.
      > If not, is there a way to create quickly custom dialog, with only[/color]
      two[color=blue]
      > buttons, returning 'true' or 'false'? Would I have to use forms to
      > return value from my custom dialog?
      > Thanx for any help.[/color]

      If there is, it's either new (beyond v1.3 - I haven't caught up with
      DOM yet), or browser-specific. You could use window.open to load a
      small HTML page with two images, then set a global variable, or call a
      function (better, so you don't have to poll), in the parent window.
      Dirty, I know, but simple.

      Mike

      --
      Michael Winter
      M.Winter@[no-spam]blueyonder.co.u k (remove [no-spam] to reply)


      Comment

      Working...