Link to home
Start Free TrialLog in
Avatar of nitinafre
nitinafre

asked on

'Yes', 'No' and 'Cancel'

Hello Experts,
   The predefined methods in javascript is alert, with ok button, confirm with 'Ok' and 'Cancel' button and prompt which I don't need. I want the method to show the dialog box with 'Yes', 'No' and 'Cancel' button. Is there any method for that. It will better if we can give the customize name to buttons. That will be additional.
Thanx in advance.
Nitin
Avatar of Mark Franz
Mark Franz
Flag of United States of America image

I don't think this is possible...  The Alert and Confirm methods are predefined.
Avatar of VincentWong
VincentWong

Yup.
There are only 3 predefined functions namely
window.alert(),
window.confirm(),
window.prompt in javascript.

alert have 1 button (ok)
confirm have 2 buttons (ok,cancel)
prompt have 2 buttons (ok, cancel)

Good Luck
And I can't find any predefined function in the client-side javascript1.3 reference and guide from iplanet.

If you want the latest reference and standard of javascript, you can go to

http://docs.iplanet.com/docs/manuals/javascript.html

(But the spec there do not designed for IE, so you can find sth only defined by IE)
typo. can't find sth only defined by IE
there is a way , but i think it works only in IE

build a html page with 3 buttons in it : OK, CANCEL and NO.. put in there everything you want

and then use window.showModalDialog(..) to display this html page.. (read MSDN for more details)

rgds
Or use a layer - works in any v4 browser

Michel
PS: If you were going to use IE specific code you might as well use an msgbox

Michel
 The modal window option, or the VB options only work in IE, though you could just use a plain new window for netscape, personally I would go with Mplunjan's sugestion of a layer...best all round option there....


  Regards
  JB
Some more points would be welcome ;-)

<html>
<head>
     <title>Prompt using window</title>
</head>

<body>
<script>
/* prompt function
   (c) copyright 2000-2001 Michel Plungjan michel@irt.org */
function showMsg(msg,title) {

  text = '<form>';
  text += '<table border=2><tr><td bgcolor=blue>'
  text += '<font color=white><b>';
  text += title;
  text += '</b></td></tr><tr><td bgcolor=lightgrey>';
  text += msg;
  text += '</td></tr><tr><td bgcolor=lightgrey><center>';
  text += '<input type="button" value="Yes" onClick="window.showResult(1)">';
  text += '<input type="button" value="No" onClick="window.showResult(2)">';
  text += '<input type="button" value="Cancel" onClick="window.showResult(3)">';
  text += '</center></td></tr></table>';
  text += '</form>';  
  if (document.all) {
     mDiv = document.all.msgDiv;
     mDiv.innerHTML = text;
     mDiv.style.visibility = 'visible';
  }
  else if (document.layers) {
     mDiv = document.layers['msgDiv'];
     with (mDiv.document) {
        write(text);
        close();
     }
     mDiv.visibility = 'visible';
  }
  else if (document.getElementById) {
     mDiv = document.getElementById('msgDiv');
     mDiv.innerHTML = text;
     mDiv.style.visibility = 'visible';
  }    

}
function showResult(result) {
   alert('User answered: '+result)
  if (document.all) {
     mDivSt = document.all('msgDiv').style;
  }
  else if (document.layers) {
     mDivSt = document.layers['msgDiv'];
  }
  else if (document.getElementById) {
     mDivSt = document.getElementById('msgDiv').style;
  }    
  mDivSt.visibility = 'hidden';
}
</script>
<a href="#" onClick="showMsg('Hello','title'); return false">layer alert</a>
<div style="position:absolute;top:300;left:400;visibility:hidden" id="msgDiv"></div>
</body>
</html>
Sorry, old title

Michel
Avatar of nitinafre

ASKER

wow, thatnks for all the 'MESSAGE'. well even ididn't find any thing on that, thats why i came here. Making of another html for that was in my mind infact, but i thouht if there is any solution. i'll try the example of Michel. lets see. in fact i didn't know much about layers, if u can tell me a bit regarding that.
Thanks for all
Nitin
It is not possible to change the buttons using Javascript. The text in the buttons depends on the Language that IE and Windows is using. For example, I am using IE and Windows in Spanish, the name of the buttons in the dialog box are "ACEPTAR" instead of "OK" and "CANCELAR" instead of "CANCEL". This is automatic. If Windows and IE were in Japanese it'll probably display something in Japanese....

Anyway, there is no way to do what you want, at least, not using the ALERT method in Javascript. You could use your own made-by-you message box......
Good point, the original question was, "can I change the default buttons..." (more or less), not can I create my own dialog box with custom buttons...

Mikes suggestion is a good one if you want to use DHTML, it's not really what you asked, but it will do...
The name is Michel, please...

Michel
Actually tried to made the message box. But I want to pass the parameter to html page for displaying message and names of the button. In showModalDialog, I was trying to call asp but don't seems to be possible so easily. So I can pass the parameter to html page then might possible. So any suggestion at that ground?
Nitin
Sorry Michel, no offense intended.
In my script, change

                     function showMsg(msg,title) {

                      text = '<form>';
                      text += '<table border=2><tr><td bgcolor=blue>'
                      text += '<font color=white><b>';
                      text += title;
                      text += '</b></td></tr><tr><td bgcolor=lightgrey>';
                      text += msg;
                      text += '</td></tr><tr><td bgcolor=lightgrey><center>';
                      text += '<input type="button" value="Yes" onClick="window.showResult(1)">';
                      text += '<input type="button" value="No" onClick="window.showResult(2)">';
                      text += '<input type="button" value="Cancel" onClick="window.showResult(3)">';
                      text += '</center></td></tr></table>';
                      text += '</form>';

to


                     function showMsg(msg,title,b1,b2,b3) {

                      text = '<form>';
                      text += '<table border=2><tr><td bgcolor=blue>'
                      text += '<font color=white><b>';
                      text += title;
                      text += '</b></td></tr><tr><td bgcolor=lightgrey>';
                      text += msg;
                      text += '</td></tr><tr><td bgcolor=lightgrey><center>';
                      text += '<input type="button" value="'+b1+'" onClick="window.showResult(1)">';
                      text += '<input type="button" value=""'+b2+'" onClick="window.showResult(2)">';
                      text += '<input type="button" value=""'+b3+'" onClick="window.showResult(3)">';
                      text += '</center></td></tr></table>';
                      text += '</form>';  

and the link to
<a href="#" onClick="showMsg('Hello','title','Yes','No','Cancel'); return false">layer alert</a>

or use an array of names - also good if you may have different number of buttons

Michel
If I say that the showModalDialog will be the better option but there must be the way to find the way by which rather calling an HTML page, we can call an ASP page. So that we can pass the parameters easily. What the Michel has given is not what exaclty I want. I am too findong on that line and still trying but hope you may get it soon. pls
Nitin
ASKER CERTIFIED SOLUTION
Avatar of Michel Plungjan
Michel Plungjan
Flag of Denmark image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Well I think i should accept your answer. With the showModalDialog function I got what I want and it is working very fine. Thanx.
Nitin
May I then ask why I only got a B? You already gave very little points - why make it worse?

Michel
Well Sorry but what is that "B"? And it is not that I reduced points. I was not having that much of points when I posted the question. Well if now possible to improve then I am ready. Just tell me.