Count function
Description
The count operator returns the number of rows in a form/formvariable.
Syntax
count(formname[<expression>])
|
Example
1. The following sample code, added to the on submit block, checks
for uniqueness of a record. If the name specified in the form data already
exists in the team_member form, the data is not submitted.
on submit
{
if (count(team_member[name == input.name]) > 0)
{
cancel submit;
}
}
|
where,
team_member - is the name of the form.
team_member [name == input.name] - selects all the team_members
whose name is equal to the name currently entered in the name field.
input.name - it is the value for the field "name" given
by the user while submitting the form
count - count operator returns the number of team members whose
name is equal to input.name
2. The following sample code, added to the on sumbit block,
limits the number of records in a form.
on submit
{
if(count(Employee)>= 20)
{
alert("No more registrations allowed"); cancel submit;
} }
|
where,
Employee - is the name of the form
count - count operator returns the number of records in the Employee
form.
|