Reputation: 317
How can I check whether password match or not in primefaces + javascript? I have used like this
function checkPass(){
var pass1 = document.getElementById('password');
var pass2 = document.getElementById('confirmPassword');
lert(pass2);
}
but getting null value! In primefaces I called like onkeyup="checkPass(); return false;"
Upvotes: 2
Views: 3966
Reputation: 4562
To get the string value we have to use following code in JSF Primefaces like,
var pass1 = document.getElementById('password_input');
var pass2 = document.getElementById('confirmPassword_input');
Upvotes: 1
Reputation: 2910
Try this code
onkeyup="checkPass(this.value)"
And javascript code:
function checkPass(text) {
var pass1 = document.getElementById('password');
if (text == pass1.value) {
alert('match');
return true;
} else {
return false;
}
}
Upvotes: 1
Reputation: 5096
I don't understand why are you using Primefaces and not take advantage of it's power...
There is a password
tag in primefaces with a match
attribute that matches the strings between two input passwords, also you can get a feedback if a password it's weaker or stronger:
<p:panel header="Match Mode">
<p:messages showDetail="true" autoUpdate="true"/>
<h:panelGrid columns="2" id="matchGrid">
<h:outputLabel for="pwd1" value="Password 1: *" />
<p:password id="pwd1" value="#{passwordBean.password6}" feedback="true" match="pwd2" label="Password 1" required="true"/>
<h:outputLabel for="pwd2" value="Password 2: *" />
<p:password id="pwd2" value="#{passwordBean.password6}" feedback="false" label="Password 2" required="true"/>
</h:panelGrid>
<p:commandButton update="matchGrid" value="Save" />
</p:panel>
Please see this link: http://www.primefaces.org/showcase-labs/ui/password.jsf . Since you haven't specified you Primefaces version, I have to tell you that this solution is for Primefaces 3.
Upvotes: 7