New Response

« Return to the main article

You are replying to:

  1. Howdy!

    First of all, this validation logic is a great help, Jake! Good work! I'm going to use this as a standard everywhere.

    I've been in the process of adding different functions to it in order to be able to do more validation. For example, it now deals with tabbed tables (tho' could be improved), and some other issues. I have created another function which is used to see if a field value has been modified. The function pops up a js 'prompt' which the user MUST enter a value which will be saved in the document history. It works quite well, but I am struggling to integrate it into the "doSubmit" function. Here it is:

    function doSubmit(f, v){ if ( v ){ var a = new Array(); a[a.length] = [f.WhateverField, 'Whatever Field'] justifyChange( f.Field);

    if ( validateRequiredFields( f, a ) ){ return true; }else{ return false; } } else { return true; } }

    Here's the "justifyChange" function:

    function justifyChange( obj ) { var lbl = obj.name; var oldVal = obj.defaultValue; var newVal = obj.value; if (oldVal != newVal && oldVal != "" ) { var why = prompt ("For what reason has the " + lbl + " been modified?", "" ); if ( why == null ) { alert( "You must enter a reason for modifying the " + lbl + "."); return false; } else var reason = lbl + ": " + oldVal + " changed to " + newVal + " (" + why + ")"; f.History.value = reason; } }

    (I apologize if the indentations don't come out well.)

    It works fine if the user enters a reason at the 'prompt'. The prompt comes up, and the value is properly enter in the "History" field and the document is submitted. However, if a user hits 'Cancel', the document will be saved anyways. The "return false;" after the "(why == null)" doesn't seem to stop the submit!!

    I hope this is clear enough, but if you need it cleared up, please lemme know. Any help would be greatly appreciated!

    Thanks, in advance!

    Steve in Montreal.

Your Comments