In jquery form validation the keyup is not working mozilla but working fine in chrome.
here is the Javascript code
function validate() {
var msg;
if(document.myForm.userPass.value.length>5)
msg="good";
else
msg="poor";
document.getElementById("mylocation").innerText=msg;
}
here is the html code
<form name="myForm">
<input type="password" value="" name="userPass" onkeyup="validate()">
Strength:<span id="mylocation">no strength</span>
</form>
From this answer it tells that Firefox doesn't take innerText
or innerHTML
to set a value, rather it takes textContent
to set a value. So use textContent
to set your value if the browser is Firefox
function validate() {
var msg;
if(document.myForm.userPass.value.length>5){
msg="good";
}
else{
msg="poor";
}
var f=navigator.userAgent.search("Firefox"); //check if browser if FF
if(f>-1)
document.getElementById("mylocation").textContent=msg //if yes use this
else
document.getElementById("mylocation").innerText=msg //else normal approach
}
Note :- As I suggested in comment use
onkeypress
instead ofonkeyup
for keypress
andhold
events validation.
To identify different browsers you can use below code from this answer
function checkBrowser(){
c=navigator.userAgent.search("Chrome");
f=navigator.userAgent.search("Firefox");
m8=navigator.userAgent.search("MSIE 8.0");
m9=navigator.userAgent.search("MSIE 9.0");
if (c>-1){
brwsr = "Chrome";
}
else if(f>-1){
brwsr = "Firefox";
}else if (m9>-1){
brwsr ="MSIE 9.0";
}else if (m8>-1){
brwsr ="MSIE 8.0";
}
return brwsr;
}