Java Script validation Using keyup for validation does not work in mozilla
In jquery form validation keyup does not work mozilla but works 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>
source to share
From this answer , he says that Firefox does not accept or to set the value, instead of the required set value . So use to set the value if Firefox browser innerText
innerHTML
textContent
textContent
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 the comment to use
onkeypress
insteadonkeyup
to validate keyspress
andhold
.
To detect 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;
}
source to share
Try using jquery, it will work in every browser
function validate() {
console.log("validation start");
var msg;
if($("input[name='userPass']").val().length >5)
console.log("good");//msg="good";
else
console.log("poor");// msg="poor";
document.getElementById("mylocation").innerText=msg;
}
source to share