Home > DeveloperSection > Forums > Javascript Object Required using JavaScript and C#
E E Cummings
E E Cummings

Total Post:26

Points:182
Posted on    October-14-2013 7:28 AM

 C# C# 
Ratings:


 1 Reply(s)
 941  View(s)
Rate this:

I am checking the email Id of the user during registration to it is valid or not I am using the Javascript.I am getting the value of the Textbox in the function during button click and verifying it but during click of the button it shows Microsoft JScript runtime error: Object required error Can any one point out what would be wrong in my code,


My javascript Function is,


     var txt = document.getElementById("emailid").value;

    if (txt != "") {

        var at = "@"

        var dot = "."

        var lat = str.indexOf(at)

        var lstr = str.length

        var ldot = str.indexOf(dot)

        if (txt.indexOf(at) == -1) {

            alert("Invalid E-mail ID")

            obj.focus()

            return false

        }

        if (txt.indexOf(at) == -1 || txt.indexOf(at) == 0 || txt.indexOf(at) == ltxt) {

            alert("Invalid E-mail ID")

            obj.focus()

            return false

        }

        if (txt.indexOf(dot) == -1 || txt.indexOf(dot) == 0 || txt.indexOf(dot) == lstr) {

            alert("Invalid E-mail ID")

            obj.focus()

            return false

        }

        if (str.indexOf(at, (lat + 1)) != -1) {

            alert("Invalid E-mail ID")

            obj.focus()

            return false

        }

        if (txt.substring(lat - 1, lat) == dot || txt.substring(lat + 1, lat + 2) == dot) {

            alert("Invalid E-mail ID")

            obj.focus()

            return false

        }

        if (txt.indexOf(dot, (lat + 2)) == -1) {

            alert("Invalid E-mail ID")

            obj.focus()

            return false

        }

        if (txt.indexOf(" ") != -1) {

            alert("Invalid E-mail ID")

            obj.focus()

            return false

        }

    }

    return true

}



Andrew Deniel
Andrew Deniel

Total Post:29

Points:203
Posted on    October-14-2013 7:51 AM

Check if your control is "runat=server" if so, the rendered html control name should be something like: #ctl00_ContentPlaceHolderMain_emailid.

Try changing this:

var txt = document.getElementById("emailid").value;

to this:

var txt = document.getElementById('<%=emailid.ClientID %>').value;

The ClientID will give you the full name in case the control is inside a content panel.

On the other side you are accessiong the property obj.focus()and I can't see obj declared inside the scope.


Modified On Oct-16-2013 10:18:47 AM

Don't want to miss updates? Please click the below button!

Follow MindStick