Client Side Validation using Custom Java Script

Hello Friends,

I want to do a simple client side validation using custom java script.

I have a view with a text field and command button. I also have a output–>script block added to the view.

My requirement is very simple as follows. On clicking the button, a java script function for ex: validate() should be called. This source code of the function should reside in “Script block”

The function “validate()” should check whether or not the text field is empty. That it should return either true or false to the calling position in this case the command button. Then the java script code on “Onlick” should just " alert "the return value.

Any ideas?

Hi Sivaraman,

I believe you can achieve the functionality without script block also.

In the command button onClick event(Client Side Validations)
read the value from the textbox control and check the length then alert the user

Javascript

var pNo = CAF.model(’#{activePageBean.clientIds[’’]}’).getValue();

if(pNo.length==0)
{
alert(“Please enter Passport / ID No”);
return;
}

Regards,
Sunil_N