spacer

Webref WebRef   Sitemap · Experts · Tools · Services · Newsletters · About i.com

home / experts / dhtml / column22
Developer News
Google to Shake Up Browsers With Own Launch
Mozilla's Ubquity Mashup: For The Masses?
iPhone Users Just Want to Have Fun
Logo

JavaScript Enhancement with VBScript
the JavaScript functions


newAlert()

Our first function, newAlert(), is to be used in place of the alert() method:

IE4 = document.all;
function newAlert(title,mess,icon,mods) {
   (IE4) ? makeMsgBox(title,mess,icon,0,0,mods) : alert(mess);
}

If our script does not have browser detection variables already defined, we must define one to isolate Explorer 4:

IE4 = document.all;

newAlert() expects four arguments:

  1. title - a string to be displayed in the dialog title bar
  2. mess - a string to be displayed as the message to the user
  3. icon - an integer between 0 and 4, inclusive, denoting the icon to be displayed (refer to table on earlier page)
  4. mods - an integer, either 0 or 1, denoting the modality of the dialog (refer to table on earlier page)

An alert-type dialog is for providing information to the user, only. We, therefore, do not have an argument to denote button group or button default. The OK button is the only one we make available.

When newAlert() is called, it checks for Explorer. If Explorer is being used, it calls makeMsgBox(), our VBScript function, passing the four arguments, plus 0 as the fourth and fifth arguments of makeMsgBox(), since we can only use the OK button.

If Explorer is not the browser being used, the regular JavaScript alert() method is called.

Make your own newAlert() dialog using the form below. We don't check your input, so type carefully to avoid errors.

newConfirm()

Our newConfirm() function replaces JavaScript's confirm() method:

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;
}

newConfirm() takes five arguments:

  1. title - a string to be displayed in the dialog title bar
  2. mess - a string to be displayed as the message to the user
  3. icon - an integer, either 0 or 1, denoting whether no icon or the Question icon is displayed.
  4. defbut - an integer between 0 and 1, inclusive, denoting the default button
  5. mods - an integer, either 0 or 1, denoting the modality of the dialog

A confirm dialog asks a Yes or No question, so we allow only the Yes/No button group. The icon can either be the Question icon or nothing. The default button, it follows, can be either the first or the second (0 or 1).

When newConfirm() is called, it first checks for Explorer. Then it processes the icon argument, to avoid errors. If the icon value is not 0, then 2 (the Question icon) is assumed. In the same way, defbuts is checked and if not zero (0), a value of 1 is assumed. The VBScript makeMsgBox() function is called, passing the required six arguments, and stores the return value from makeMsgBox() to the retVal variable. Notice that the fourth argument is hard-coded as 4 (the Yes/No button group) as this is the only option we allow for confirm dialogs.

We use confirm dialogs when we need a user decision. Our script then branches according to the decision. The JavaScript confirm() method returns a Boolean: true if the user clicked OK, and false if the user clicked Cancel. It is assumed that you are familiar with JavaScript confirm dialogs, and processing the value returned. Here, we must ensure that newConfirm() returns a Boolean. Since we are using the Yes/No button group, the return value can be either 6 (Yes) or 7 (No). We, therefore check for a makeMsgBox() return value of 6. If it is 6, retVal is true. Any other value makes retVal equal to false:

retVal = (retVal==6);

If Explorer is not the current browser, then the JavaScript confirm() method is called. In either case, the value returned by newConfirm(), retVal, is either true or false.

Make your own newConfirm() dialog using the form below. We don't check your input, so type carefully to avoid errors.


newPrompt()

The newPrompt() function replaces JavaScript's prompt() method:

function newPrompt(title,mess,def) {
   retVal = (IE4) ? makeInputBox(title,mess,def) : prompt(mess,def);
   return retVal;
}
  1. title - a string to be displayed in the dialog title bar
  2. mess - a string to be displayed as the message to the user (a prompt)
  3. def - a string to be displayed in the input area as the default response

These are the same three arguments expected by makeInputBox(), so we simply pass them along if Explorer is being used. Otherwise, the prompt() method is called with the required two arguments. In either case, the return value, a string, is assigned to retVal.

Make your own newPrompt() dialog using the form below. We don't check your input, so type carefully to avoid errors.



IEBox()

The newAlert(), newConfirm() and newPrompt() functions produce results in any JavaScript browser. For Explorer 4 users, however, they produce an enhanced, more informative dialog, but with the same functionality.

For those working in Explorer-only environments, we've provided a fourth function IEBox(), which filters out other browsers and produces a dialog for Exlorer users only:

function IEBox(title,mess,icon,buts,defbut,mods) {
   retVal = (IE4) ? makeMsgBox(title,mess,icon,buts,defbut,mods) : null;
   return retVal;
}

IEBox() gives full access to all dialog "look" variations possible with our makeMsgBox() function. It takes the same six arguments as makeMsgBox(), does no filtering and passes them on.

Make your own IEBox() dialog using the form below. We don't check your input, so type carefully to avoid errors.



We'll repeat the full script on our final code page, but first, let's wrap-up.


Produced by Peter Belesis and



JupiterOnlineMedia

internet.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

Jupitermedia Corporate Info


Legal Notices, Licensing, Reprints, & Permissions, Privacy Policy.

Advertise | Newsletters | Tech Jobs | Shopping | E-mail Offers

Solutions
Whitepapers and eBooks
Intel PDF: Virtualization Delivers Data Center Efficiency
Intel eBook: Managing the Evolving Data Center
Microsoft Article: BitLocker Brings Encryption to Windows Server 2008
Symantec eBook: The Guide to E-Mail Archiving and Management
Microsoft Article: RODCs Transform Branch Office Security
Go Parallel Article: James Reinders on the Intel Parallel Studio Beta Program
Avaya Article: Advancing the State of the Art in Customer Service
Adobe Acrobat Connect Pro: Web Conferencing and eLearning Whitepapers
Avaya Article: Avaya AE Services Provide Rapid Telephony Integration with Facebook
Go Parallel Article: Getting Started with TBB on Windows
HP eBook: Storage Networking , Part 1
MORE WHITEPAPERS, EBOOKS, AND ARTICLES
Webcasts
Intel Seminar: Efficiencies in Hardware/Software Virtualization
HP Webcast: Disaster Recovery Planning
Go Parallel Video: Performance and Threading Tools for Game Developers
HP Video: StorageWorks EVA4400 and Oracle
HP Webcast: Storage Is Changing Fast - Be Ready or Be Left Behind
MORE WEBCASTS, PODCASTS, AND VIDEOS
Downloads and eKits
IBM TCO eKIT: Your IT Budget is Under Attack, Get in Control
IBM Energy Efficiency eKIT: Learn How to Reduce Costs
30-Day Trial: SPAMfighter Exchange Module
Red Gate Download: SQL Toolbelt and free High-Performance SQL Code eBook
Iron Speed Designer Application Generator
MORE DOWNLOADS, EKITS, AND FREE TRIALS
Tutorials and Demos
Microsoft Article: Silverlight Streaming--Free Video Hosting for All
Featured Algorithm: Intel Threading Building Blocks - parallel_reduce
HP Demo: StorageWorks EVA4400
MORE TUTORIALS, DEMOS AND STEP-BY-STEP GUIDES
webref The latest from WebReference.com Browse >
The Partial Function Application in JavaScript · Creating Dynamic RSS Feeds with Ajax · Performance Optimizations for High Speed JavaScript
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Cablevision Deploys More Hotspots for Commuters · Dell Joins the Netbook Movement with its Inspiron Mini 9 · It's Official: Dell Enters the Netbook Fray

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

URL: http://www.webreference.com/dhtml/column22/js-vbNewjs.html