Textbox HTML Forms with Nag

Is current?: 

The textbox-nag template textbox-nag.htm is a type of HTML form that is a variant of the textbox.  The nag functionality uses Javascript code to alert the user if he or she has not responded to all items.  For free-form text box input, we define a minimum length that is required of each entry. This nag alerts the user once, and after that, the user is free to proceed to the next task, even without completing the items.

The use of the fake button and the distinction between the fake button and real button is explained in the dropdown-nag entry. The onclick event handler in the fake button on line 78 is the function donag().  When the user clicks on the Continue button, donag() checks if the user had previously clicked this button.  If this is the first click and if the responses are incomplete then the user is alerted.  If this is the second click, or if the items have been completed, then the form is submitted using document.form1.submit().  The donag()for textbox is below:

<script type="text/javascript">

  var nnag=0;

  function donag() {

    nnag++;               // increment by 1

    var allanswered=true; // assume everything is complete

    var minlen=3;
    if (document.form1.tbitem1.value.length<minlen) allanswered=false
;//check length of tbitem1

    if (document.form1.tbitem2.value.length<minlen) allanswered=false;//check length of tbitem2

    if (document.form1.tbitem1.value.length==0) document.form1.tbitem1.value = "."; //set to .
    if (document.form1.tbitem2.value.length==0) document.form1.tbitem2.value = "."; //set to .
    if (!allanswered && nnag<=1)
        alert("Please type responses that have "+minlen+" or more characters.\nThis reminder
                    will appear once.");

        else document.form1.submit(); //else submit the form


If you would prefer to define unique minlengths for each item, that can be done by defining variables such as minlen1 and minlen2, setting them to different values, and then using them in the corresponding lines that check the lengths of the variables.

What happens if the user does fails to type in any input?  In this case, the length of the variable will be zero.   In such cases, we substitute the value of “no input” with a period.  Note that we haven’t included the missing value feature in the standard textbox template. In that file, non-responses are stored as the null string (nothing).