Click here to Skip to main content
15,881,898 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
javascript validation working fine in chrome.not working in firefox.while click send button in firefox it shows message "else"

What I have tried:

JavaScript
<script> 
function check_empty() {
var str=true;
var user_name = /^[A-z]+$/;
var email_val = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/;
var phnor =/^[2-9]\d{2}-\d{3}-\d{4}$/;
var pwd = /^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[$@$!%*?&])[A-Za-z\d$@$!%*?&]{8,}/;
if (!document.form.uname.value.match(user_name))
				{
				document.getElementById('msg1').innerHTML="*Please enter a username*";
				 
				str=false;
				}
				else if (document.form.uname.value != "")
				 {
				document.getElementById('msg1').innerHTML="";
				
				str=false;
				 }
				 
				 
if (!document.form.email.value.match(email_val))
				{
				document.getElementById("msg3").innerHTML="Please Enter Valid Email ID";
				str=false;
				}
				else if (document.form.email.value != "")
				 {
				document.getElementById("msg3").innerHTML="";
				str=false;
				 }
Posted
Updated 22-May-17 2:10am
Comments
Suvendu Shekhar Giri 16-May-17 2:53am    
But there is no alert/label/logic there with message "else" in you code!
Please show the correct block of code or correct message.
GrpSMK 16-May-17 2:55am    
sorry message"false" wrongly typed and posted
Suvendu Shekhar Giri 16-May-17 3:02am    
Seems, you are still missing something. In each of the IF and ELSE block, you have set value of str=false, so at the end you'll get false as value.
GrpSMK 16-May-17 3:04am    
but working fine in chrome?
omerkamran 22-May-17 7:52am    
debug your code, i guess your firefox is generating error in IF statement

1 solution

you are also missing the complete If else structure
JavaScript
If ()
{....}
else if()
{...}

else //you have missed this Else
{...}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900