39 users online (0 members and 39 guests)  


  Results 1 to 2 of 2

Related

  1. One Click Login    Forum: Javascript Forum
    Replies: 1
  2. Replies: 8
  3. Replies: 0
  4. Group null values and show them    Forum: PHP Forum
    Replies: 0
  5. Error MySQL Error: 1064 - subqueries    Forum: PHP Forum
    Replies: 0
  1. #1
    cajunaggie87's Avatar
    New User

    Status
    Offline
    Join Date
    Jun 2010
    Posts
    2

    login is null error

    I have a webpage that has a login button. When this button is clicked, I want to run a function that is located in a .js file (validate.js).

    At the top of my html page I have:
    HTML Code:
    <script type = "text/javascript" src="Scripts/Validate.js"></script>
    and then I have the button as a user control and put it on the page with:
    HTML Code:
    <uc:Login id="_login" runat="server"/>
    Then directly below that I have:
    HTML Code:
    <script type="text/javascript">
       var element = '<%=_login.ClientID %>';
       call(element);
    </script>
    Validate.js:
    Code:
    function call(element)
    {
    	var login = document.getElementById(element);
    	alert(element + login);
    	login.onclick = validate;
    }
    function validate()
    {
       //do something
    }
    And when I run the page, I get a javascript error saying that login is null. What could be my problem?

  2. #2
    cajunaggie87's Avatar
    New User

    Status
    Offline
    Join Date
    Jun 2010
    Posts
    2

    Re: login is null error

    I figured it out. I was trying to access the onclick event of a button with id of _login within the user control. I had to put the javascript getting the clientId of that button within the code for that usercontrol. Otherwise, I was getting the clientID of the usercontrol and not the button.



Tags for this Thread