Dialogs for offering user interaction are an essential element of Online Communication. Alas, standard HTML holds only very simple types of dialog. How you can easily equip your documents with even quite sophisticated dialogs, you can read in this article.
For a real application based on a Dialog see my article
Involve the Users - Let Them "Customize" Your Document!
(there, in UserMenu click items New int. Note , New ext. Note
or, when the mouse is on a note, Update Note )
If you want to include user interactivity to an online document, you are soon in a dilemma:
| - | If you want to get some sophisticated points across, |
| - | but you give the readers only a few simple operations to get hands-on experience |
| _ | you are losing credibility. |
| - | you have to spend a great deal of your time for coding HTML and Javascript |
| - | in the end, not much time might be left to write on your points |
| _ | your readers might feel overwhelmed by the user interactivity (in turn you are losing credibility again). |
So I developed some Javascript functions for handling most of the user interactivity. To apply them in Online Communication, all you have to do are two steps:
|
|
This time in particular I would like to invite you: Please do spy on the source code! In view of the effort involved, you might sometimes wonder if a demo was really implemented as I said before, or if there was any trick at the bottom of it. To do that, you are explicitly asked to right-click anywhere on your browser and to click "View Source" in the context menu. (Don't forget to spy on both, this main window as well as the dialog window!)
The most efficient way for preparing a dialog is the following:
HTML-file from which the dialog is called. In its <HEAD>
</HEAD> part, or between the tags </BODY> and </HTML> , include the following line:
Details about this function you can find in section DialogCaller()
For all the variables you want to pass to a dialog (= expose to user interaction), in the DialogCaller file there should be any of the following:
<TABLE>
<TR>
<TD>(prompt)</TD>
<TD COLSPAN="x"><TEXTAREA NAME="
" COLS="
" ROWS="
"></TEXTAREA>
</TD>
</TR>
<TR>
<TD>(prompt)</TD>
<TD COLSPAN="x"><INPUT TYPE="
" NAME="
"></TD>
</TR>
:
</TABLE>
Inputs of a group (TYPE= CHECKBOX or RADIO ) should all have the same NAME .
Details about this function you can find in section DialogButtons()<TR> <TD></TD> <SCRIPT>DialogButtons()</SCRIPT> </TR>
Besides the usual keyboard handling of TEXTAREA and standard HTML inputs, in a semi-modal dialog there are some extra key strokes:
| Ctrl + ENTER | Pressing this key combination returns the current input values to the DialogCaller window and closes the dialog window. This behavior is suppressed if
|
| Ctrl + space | Pressing this key combination "blurs" the dialog window:
|
| If the dialog window has a help file of any browser-compatible type, it will be displayed in the same dialog window (replacing the dialog UIF). After reading, to return to the dialog, the users should press this key combination (i.e. you should remind them to do so). | |
| Esc | The dialog window is closed without returning input values to the DialogCaller window |
Frequently you will want to have a variable offered in a dialog that is internal to the main window, i.e. it is not visible there.
Best would be, obviously, if the value entered by the user would be assigned to the variable directly. Unfortunately, that's not possible. Instead, you can provide an input of TYPE="hidden" . This input is not visible to the user, though you can handle it just like any other input:
In sub-section DialogCaller() - Options you will see how you can trigger your own function ("custom function") once fresh dialog return values are available. In that function you can access the user entry and assign it to the internal variable:
It will be useful if that hidden input has an ID similar to the variable's identifier. Though you should watch out not to call it identically.
The part
Frequently you will want to prompt the user for an input whose value is to be assigned to any attribute of an object.
You could handle that, of course, in a somewhat complicated way: For each of them provide 'hidden' inputs in the main window, call the function Dialog() with an option func= referring to a Javascript function handling all the re-assignments of the input values returned from the dialog.
You can, however, also have the dialog assign them directly to the object's attributes.
To do that, simply give qualified names to the inputs in the dialog window (i.e. names comprising at least one '.'), reflecting where to assign them to. For example:
Let's assume, you have a link anchor in your main window to which you want to prompt the user for the destination and the label:
In the dialog window there should be two inputs with qualified names. Their types can be any of the types listed in section DialogCaller file (except, of course, the first one, an object's attributes).
| Destination: | <INPUT NAME="link.href" > |
| Label: | <INPUT NAME="link.innerText" > |
In the main window you need no extra provisions.
When the user blurs or closes the dialog, these input values will be assigned directly to the respective attributes.
One input character is not reflected in a note's contents: the line break .
The reason is that the text entered by the user in the TEXTAREA of the dialog is interpreted not as text but as HTML. In HTML a line break is ignored and replaced by a space. So, tell the users that where they want to see a line break in the note, they should code it as <BR> .
As well, a number of consecutive spaces in the TEXTAREA of the dialog is reduced to one space only.
This function is needed to handle the liaison with the dialog file: checking periodically for fresh return values, and closing it if the dialog window is still open when the DialogCaller window is about to close.
For its syntax, the place where to call it, and its options see the following sub-sections.
options is a string of keyword options, separated by blank space. A keyword option is of the form keyword=value If the value comprises blank spaces it should be bracketed in single or double quotes ( keyword='value' or keyword="value" ), depending on the context.
If no options are needed, the function should be called with an empty arguments list: DialogCaller()
For a table of the options currently available see sub-section DialogCaller() - Options.
Function DialogCaller() can be called anywhere before or after the <BODY> </BODY> part of the DialogCaller file.
Currently the following options are available:
| time | Time interval for checking for return values, in milliseconds. By default, every 500 milliseconds will be checked if the dialog window has returned values. This timing will be enough for most applications, while still not overburdening the user's computer. Only in very time-critical applications you will want the DialogCaller window to respond faster. |
| func | In many applications you will have a custom function for processing the value(s) returned by the dialog. By this option you can have it triggered once fresh return values are available. Just set this option to the code by which your custom function is to be called, i.e.
func=YourFunction([arguments]) |
This function is needed for
options is a string of keyword options, separated by blank space. A keyword option is of the form keyword=value If the value comprises blank spaces, it should be bracketed in single or double quotes ( keyword='value' or keyword="value" ), depending on the context.
If no options are needed, the function should be called with an empty arguments list: DialogCaller()
For a table of the options currently available see sub-section DialogFooter() - Options.
Function DialogFooter() can be called only after the <BODY> </BODY> part of the Dialog file.
This is the function to be called for launching a dialog. Usually this will be done when the user is clicking a BUTTON or SUBMIT :
is the button label that the user will see on screen (e.g. Dialog or similar).
| input id's | List of access codes of those inputs you want to expose to user interaction (separated by a blank space). Note that the same codes will be expected as names in the Dialog file for all the inputs to be offered to the user (see point 2 in section Preparing a Dialog File). This list is needed only for those inputs where you want to have start values presented to the user. If it is ok when the dialog window is popping up with empty inputs, you can leave this list empty. |
| Options | Optional fine-tuning of the function's behavior. For a table of the options currently available see sub-section |
This function can be called at any place in the main window, wherever you think it's user-friendly. Normally its call will be part of a BUTTON or SUBMIT input - when the user is clicking the button (or pressing the ENTER-key, in case of SUBMIT ) a dialog is launched with the attributes given as arguments:
You can also launch disparate dialogs in a common document, if you call function Dialog() with different options uif= , different button settings (options noblur and/or readonly ) and/or different input names. For details as to the coding of inputs see the following sub-section.
For efficiently preparing your dialog window, and for processing the values returned by a dialog, you will want to know details as to the coding of inputs.
Preparing a Dialog Window
By default, the dialog is launched with dialog window Dialog.html . This is a very basic dialog-UIF with one input only, a text area as follows:
The inputs of a dialog can be:
Processing Return Values
All return values will be taken to be plain ASCII-strings.
For dialog inputs of type radio and checkbox there is a special interpretation:
Currently the following Dialog() options are available:
| width=number | Sets the width of the dialog window. Default: 850 |
| height=number | Sets the height of the dialog window. Default: 565 |
| top=number | Sets the top position of the dialog window relative to the upper-left corner of the desktop. Default: 70 |
| left=number | Sets the left position of the dialog window relative to the upper-left corner of the desktop. Default: 100 |
| center=yes|no|1|0 | Specifies whether to center the dialog window within the desktop. Default: yes |
| status=yes|no|1|0 | Specifies whether to add a status bar at the bottom of the window. Default: yes |
| resizable=yes|no|1|0 | Specifies whether to display resize handles at the corners of the window Default: yes |
| noblur | The dialog will have no Blur button, i.e. input values are returned only when the dialog is closed. Default: no noblur |
| readonly | The dialog will have no Close button, i.e. input values cannot be returned but only aborted (by clicking the Esc key). Default: no readonly |
| For details to button handling, see also Keyboard Inputs | |
| help= |
The dialog will have a Help button. When the user is clicking it, the given help file will be displayed. For a comprehensive dialog it will be quite user-friendly to provide a help file explaining the details. Default: no help file. Notes:
|
| func= "custom function([arguments])" |
Establishes the interrelation of the dialog functions and a custom function (if any). The custom function is triggered in the main window whenever fresh dialog return values are available. Default: no custom function |
Auxiliary function to
This function can be called out of HTML code by bracketing it in <SCRIPT> <SCRIPT> :
The optional argument "func([arguments])" is a string giving the code of calling a custom function func() , if any. Optionally this call can be done with its arguments:
If given, the custom function (with the given arguments, if any) will be called every time the dialog is about to return values to the main window.
That way it can be used for checking the plausibility of user inputs. If they are found implausible, a clarifying alert should be displayed to the user right out of the custom function.
For example, the dialog pertaining to the trial pad of this article has a plausibility check built in. Leave all inputs empty and try to close or blur the dialog. A message will come up ( Error: All inputs empty ) and the dialog remains on screen.
This function is intended to be called in a table of inputs and their labels, e.g. like in the following coding scheme:
<TABLE>
<TR VALIGN=top>
<TD>Label_1</TD>
<TD colspan=n>
<INPUT TYPE="
" NAME="
" ACCESSKEY="
"
>
</TD>
</TR>
:
<TR>
<SCRIPT>DialogButtons(["func([arguments]]")</SCRIPT>
</TR>
</TABLE>
TYPE=" " determines the type of input presented to the user ( checkbox , file , password , radio or text )
NAME=" " are the names by which the individual inputs will be handled by the dialog functions. They should be identical to the identifiers of the respective values in the main window.
ACCESSKEY=" " is the attribute needed to make an input accessible by keyboard - a good idea for extra user-friendliness! (Details: see sub-section Keyboard Handling)
n is the maximum number of buttons this dialog window will be launched with. (See Dialog Options of function