DHTML Lab: JavaScript Enhancement with VBScript; The Complete Code | WebReference

DHTML Lab: JavaScript Enhancement with VBScript; The Complete Code

Logo

  JavaScript Enhancement with VBScript
  SPECIAL EDITION; the director's cut

Include the following scripts in the HEAD of your document (JS script must come first to set page script language default):

<SCRIPT LANGUAGE="JavaScript" TYPE="text/javascript">
<!--
IE4 = document.all;
function newAlert(title,mess,icon,mods) {
   (IE4) ? makeMsgBox(title,mess,icon,0,0,mods) : alert(mess);
}
function newConfirm(title,mess,icon,defbut,mods) {
   if (IE4) {
      icon = (icon==0) ? 0 : 2;
      defbut = (defbut==0) ? 0 : 1;
      retVal = makeMsgBox(title,mess,icon,4,defbut,mods);
      retVal = (retVal==6);
   }
   else {
      retVal = confirm(mess);
   }
   return retVal;
}
function newPrompt(title,mess,def) {
   retVal = (IE4) ? makeInputBox(title,mess,def) : prompt(mess,def);
   return retVal;
}
function IEBox(title,mess,icon,buts,defbut,mods) {
   retVal = (IE4) ? makeMsgBox(title,mess,icon,buts,defbut,mods) : null;
   return retVal;
}

//-->
</SCRIPT>
<SCRIPT LANGUAGE=VBScript TYPE="text/vbscript">
<!--
Function makeMsgBox(title,mess,icon,buts,defbut,mods)
   butVal = buts + (icon*16) + (defbut*256) + (mods*4096)
   makeMsgBox = MsgBox(mess,butVal,title)
End Function
Function makeInputBox(title,pr,def)
   makeInputBox = InputBox(pr,title,def)
End Function

-->
</SCRIPT>

Now, you can call the four JavaScript functions from anywhere in your page. Take care to pass the correct number of arguments:

newAlert(title,message,icon,modality)
        string, string, 0-4, 0/1

example: newAlert("DHTML Lab","No confusing captions",4,0)


newConfirm(title,message,icon,default button,modality)
          string, string, 0/1,       0/1,      0/1

example: newConfirm("DHTML Lab Confirmation Request","Are you confused yet?",1,1,0)


newPrompt(title,message,default response)
         string, string,    string

example: newPrompt("DHTML Lab User Input Request","Enter your name, please:","Ishmael")


IEBox(title,message,icon,button group,default button,modality)
     string, string, 0-4,       0-5,      0-2,        0/1

example: IEBox("DHTML Lab Explorer Dialog","All options enabled",1,2,2,1)



Produced by Peter Belesis and

All Rights Reserved. Legal Notices.
Created: Nov. 18, 1998
Revised: Nov. 18, 1998

URL: http://www.webreference.com/dhtml/column22/allCode.html