BFry
BFry

Reputation: 915

Validation does not work in Firefox, works fine in IE

I have an email validation code on client side. It works fine/as expected in IE but somehow doesnot show error messages in Firefox.

Below is the code:

<asp:ImageButton ID="btnLink" runat="server" AlternateText="ClickHere" OnClientClick="return onCClick();" OnClick="btnLink_Click"/>  
<div id="errorEmail" runat="server"></div>

//function to validate
        function onCClick() {
//clear error message
            document.getElementById('<%=errorEmail.ClientID%>').innerText = "";
//if validation fails
            if (validateEmail() != true) {
//show error message
                document.getElementById('<%=errorEmail.ClientID%>').innerText = "Invalid Email Address.";
                return false;
            }
}

function validateEmail() {
            var emailId = document.getElementById('<%=txtEmail.ClientID%>').value;
            var emailPattern = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
            return emailPattern.test(emailId);
        }

Is there something which i should have taken care of ? My error message div is set to blank but not invisible anywhere(in that case javascript also would not have worked)

Upvotes: 0

Views: 648

Answers (2)

Pandian
Pandian

Reputation: 9126

Better you try innerHTML.. it will work..

document.getElementById('errorEmailAddress').innerHTML = "Error Message";

Upvotes: 0

epascarello
epascarello

Reputation: 207491

innerText is not cross browser, firefox uses textContent

You can use a function like this:

function changeText(elem, changeVal) {
    if ((elem.textContent) && (typeof (elem.textContent) != "undefined")) {
        elem.textContent = changeVal;
    } else {
        elem.innerText = changeVal;
    }
}

or just use innerHTML.

Upvotes: 1

Related Questions