PDA

View Full Version : checking equality of two textfield



masoud_tamizy
6 Mar 2012, 2:42 PM
how can i check equality of two field values in a form ? for example for password and retype it ?

Farish
6 Mar 2012, 5:40 PM
if you have an id attached to the fields, you could check if the two field values are equal when the user presses Submit button on the form.


var val1 = Ext.getCmp('field1').getValue();
var val2 = Ext.getCmp('field2').getValue();
if(var1 != var2)
{
alert('Passwords do not match');
return;
}
else
{
// submit the form/save the value
}

OR you can create a validator function which checks if both fields have equal values and if they dont, you could display a tooltip and/or disable the Submit button till both fields have equal values.