最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

java - check whether password match or not in primefaces + javascript - Stack Overflow

programmeradmin1浏览0评论

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;"

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;"

Share Improve this question asked Dec 16, 2011 at 8:07 lofa inlofa in 3171 gold badge8 silver badges26 bronze badges 1
  • Is there in fact an element in the dom with an id of "confirmPassword"? – Jake Feasel Commented Dec 16, 2011 at 8:09
Add a ment  | 

3 Answers 3

Reset to default 7

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:mandButton update="matchGrid" value="Save" />  
    </p:panel>

Please see this link: http://www.primefaces/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.

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'); 

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;
  }
}
发布评论

评论列表(0)

  1. 暂无评论