JavaScript In-Question Validation

Revision as of 14:33, 29 May 2014 by Philip Lacey (talk | contribs)
Revision as of 14:33, 29 May 2014 by Philip Lacey (talk | contribs)

JavaScript validation can be applied to any field in a form not just on the outcomes. This is in field validation allows an agent to correct in real time the data whilst still having the customer on the phone. In field validation is quite straight forward to set up but some considerations are needed.


The validation is added to the onFocus, onChange and onBlur events of the question. More information on this can be found at JavaScript_Field_Events


Lets start with a few simple examples. We have a text box which stores a mobile number. We do not want to let the agent move on until a phone number is in there. Why a phone number, well if you are in a call you really should have a number to call the customer back on, so phone number should be vital.


The event is: when the agent moves into and then out of the phone number text box, we want to alert the user to put something and move them back into the phone number box.

Process

  1. Take a text box on any form. Make sure you have edit permission to this form, i.e. there is a little pencil icon to the right of every question. Icon Pencil.png
  2. Go to the very top of the editing page to find the field name. Usually in the format strCDA_X_field_Y_Z. For our example we will use the one displayed, i.e. strCDA_1170_field_0_3

JavaScript onChangeDemo QuestionEditTop.png

  1. Go down to the onChange box and enter the following
var strCDA_1170_field_0_3 = document.getElementById('strCDA_1170_field_0_3');
if (strCDA_1170_field_0_3.value == ''){
	strCDA_1170_field_0_3.focus();
	alert('Sorry but you must provide a phone number.');
}