This example script demonstrates Javascript validation when creating or editing records. To try it, click on the New record button in the applet below.
If the firstname is filled, then we validate that the lastname is also filled. If the firstname is empty, then we do not validate the lastname.
First we setup the following property:
$lens->validation = 'FIRSTNAME^%validatename( )^';
Then we define the javascript:
<script defer>
// if first name is set, then lastname must be set
function validatename()
{
if (document.phplens_ex309_edit.lens_FC_FIRSTNAME.value)
if (! document.phplens_ex309_edit.lens_FC_LASTNAME.value) {
alert('Both first and last name must be filled');
return '';
}
return 1;
}
</script>
If the javascript function returns:
|