faqts : Computers : Programming : Languages : JavaScript : Windows

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

17 of 24 people (71%) answered Yes
Recently 7 of 10 people (70%) answered Yes

Entry

How can I replace prompt with a self made dialog?

Apr 24th, 2000 07:23
Martin Honnen,


IE allows that easily with the showModalDialog function explained in
http://www.faqts.com/knowledge-base/view.phtml/aid/876/fid/124/lang/en. 

Here is an example dialog replacing a prompt:

<HTML>
<HEAD>
<SCRIPT>
</SCRIPT>
</HEAD>
<BODY ONLOAD="var answer = document.forms[0].answer; answer.focus(); 
answer.select();">
<FORM ONSUBMIT="window.returnValue = this.answer.value;
                window.close();
                return false;">
<TABLE WIDTH="100%" HEIGHT="100%">
<TR>
<TD VALIGN="middle" ALIGN="center">
<SCRIPT>
document.write(window.dialogArguments.question);
document.write('<BR>');
document.write('<INPUT TYPE="text" SIZE="40" NAME="answer"' +
  'VALUE="' + window.dialogArguments.defaultAnswer + '">');
</SCRIPT>
<BR>
<DIV ALIGN="right">
<INPUT TYPE="submit" VALUE="  OK  ">
<INPUT TYPE="button" VALUE="Cancel"
       ONCLICK="window.returnValue = null;
                window.close();"
>
</DIV>
</TD>
</TR>
</TABLE>
</FORM>
</BODY>
</HTML>

which you call as follows in another page:

showModalDialog('nameOfAboveDialogPage.html', 
  {question: 'Who is GOD?', defaultAnswer: 'Kibo'});