Saltar apartados

Classes (Exercises)

1.- It creates a page html with a form (name: form). Than said form contain a box of text and a button send.

It creates a class called check that:

  • It have a property called error1 and that have like initial value 'The field can not remain vacio'.
  • It have a property called error2 and that have like initial value 'The field has to have at least 2 characters'.
  • It have a method called tavacio that check if the field this vacio or no. In case to be vacio gives back an alert showing the value of error1. It gives back a return false. In case of not being vacio gives back a return true and executes the method slargo.
  • It have another method called slargo that check if the field has more than 2 characters or no (length). In case to have less or equal to 2 gives back an alert showing the value of error2. It gives back a return false. In case of not being vacio gives back a return true.


It inserts both methods to the submit of the form so that it check both cases.


2.- It completes the previous example.
It creates a select to select language: to choose between two values is and goes.
It extends twice the class check and flame to a comprobarva and the another checked. In the extensions defines the properties error1 and error2, so that it cost

Stop checked =
Error1: 'This field can not remain empty',
Error2: 'This field has to be longer'
For comprobarva =
Error1: 'Aquest camp no pot remain buit',
Error2: 'Aquest camp has to be més llarg'

It deletes these properties of the function check.

Now do that the messages are in a language or in another in function of the language selected.

3.- It completes the previous example.
It creates other two fields in the form. One that was a group of radii and the another a field of text.

The group of radii: To choose between PAS, PDI and others. If we marked others, when doing submit has to check that the field of text has filled up.

For this we will use the method implement.

Download PDF

Computing service Mootools


Universidad de Alicante
Carretera de San Vicente del Raspeig s/n
03690 San Vicente del Raspeig
Alicante (Spain)

Tel: (+34) 96 590 3400

Fax: (+34) 96 590 3464

For further information: informacio@ua.es, and for enquiries on this web server: webmaster@ua.es

Carretera San Vicente del Raspeig s/n - 03690 San Vicente del Raspeig - Alicante - Tel. 96 590 3400 - Fax 96 590 3464