Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 11 of 11
  1. #1
    New to the CF scene
    Join Date
    May 2013
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Javascript error "mouseOutUPN" is undefined

    Hello,

    I have a problem with my code.
    I have following files.
    - messageWCF.aspx
    and two files with javascript
    -sendMessage.js
    -validate.js

    In the messageWCF.aspx i have buttons and textboxes. When I mouseover a Button one of my textboxes should turn red.


    messageWCF.aspx
    Code:
    <script src="jscripts/validate.js" type="text/javascript"></script>
    <script src="jscripts/sendMessage.js" type="text/javascript"></script>

    sendMessage.js

    Code:
    function mouseInUPN() 
                {
                    var txtInUPN = document.getElementById("<%=txtUpn.ClientID %>");
                    txtInUPN.style.background = "#F08080";
    
                    if (document.getElementById('txtUpn').value == '') 
                    {
                        document.getElementById('txtUpn').innerHTML = txtInUPN; 
                        
                    } 
                    else if (document.getElementById('txtUpn').value != '')
                    {
                        mouseOutUPN();
                    }
    
                }
                
                    function mouseOutUPN() 
                {
                    var txtOutUPN = document.getElementById("<%=txtUpn.ClientID %>");
                    txtOutUPN.style.background = "white";
    
                    if(document.getElementById('txtUpn').value == '')
                    {
                        document.getElementById('txtUpn').innerHTML = txtOutUPN; 
                        
                    }
                    else if (document.getElementById('txtUpn').value != '')
                    {
                        txtOutUPN.style.background = "white";
                    }
                }


    validate.js

    Code:
    $(function () {
        $("li.liUPN").mouseenter(function () {
            $this = $(this);
            clearTimeout($this.data("delay1"));
            $this.data("delay1", setTimeout(function () {
                mouseInUPN();
            }, 800)
                           );
        })
    
        $("li.liUPN").mouseleave(function () {
            $this = $(this);
            clearTimeout($this.data("delay1"));
            mouseOutUPN();
        });
    });
    My problem is when I run the the soulution I get the error ""mouseOutUPN" is undefined"
    But if I put my sendMessage.js code inside the messageWCF.aspx file it runs and works.
    I also tried to put the sendMessage.js code inside validate.js file, I dident got any errors then, but the code dident launch. So when I mouseovered a button it dident happend anything to my textbox, as it should turn red.

    What am I missing?

    Thanks for all help and reply!

  • #2
    New to the CF scene
    Join Date
    May 2013
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Pota View Post
    Hello,

    I have a problem with my code.
    I have following files.
    - messageWCF.aspx
    and two files with javascript
    -sendMessage.js
    -validate.js

    In the messageWCF.aspx i have buttons and textboxes. When I mouseover a Button one of my textboxes should turn red.


    messageWCF.aspx
    Code:
    <script src="jscripts/validate.js" type="text/javascript"></script>
    <script src="jscripts/sendMessage.js" type="text/javascript"></script>

    sendMessage.js

    Code:
    function mouseInUPN() 
                {
                    var txtInUPN = document.getElementById("<%=txtUpn.ClientID %>");
                    txtInUPN.style.background = "#F08080";
    
                    if (document.getElementById('txtUpn').value == '') 
                    {
                        document.getElementById('txtUpn').innerHTML = txtInUPN; 
                        
                    } 
                    else if (document.getElementById('txtUpn').value != '')
                    {
                        mouseOutUPN();
                    }
    
                }
                
                    function mouseOutUPN() 
                {
                    var txtOutUPN = document.getElementById("<%=txtUpn.ClientID %>");
                    txtOutUPN.style.background = "white";
    
                    if(document.getElementById('txtUpn').value == '')
                    {
                        document.getElementById('txtUpn').innerHTML = txtOutUPN; 
                        
                    }
                    else if (document.getElementById('txtUpn').value != '')
                    {
                        txtOutUPN.style.background = "white";
                    }
                }


    validate.js

    Code:
    $(function () {
        $("li.liUPN").mouseenter(function () {
            $this = $(this);
            clearTimeout($this.data("delay1"));
            $this.data("delay1", setTimeout(function () {
                mouseInUPN();
            }, 800)
                           );
        })
    
        $("li.liUPN").mouseleave(function () {
            $this = $(this);
            clearTimeout($this.data("delay1"));
            mouseOutUPN();
        });
    });
    My problem is when I run the the soulution I get the error ""mouseOutUPN" is undefined"
    But if I put my sendMessage.js code inside the messageWCF.aspx file it runs and works.
    I also tried to put the sendMessage.js code inside validate.js file, I dident got any errors then, but the code dident launch. So when I mouseovered a button it dident happend anything to my textbox, as it should turn red.

    What am I missing?

    Thanks for all help and reply!

    Sorry mouseInUPN error, then mouseOutUPN error when i mouseout of the button.

  • #3
    Senior Coder
    Join Date
    Jan 2011
    Location
    Missouri
    Posts
    3,772
    Thanks
    23
    Thanked 550 Times in 549 Posts
    Code:
    document.getElementById("<%=txtUpn.ClientID %>");
    think it should be
    Code:
    document.getElementById("txtUpn.ClientID");
    Evolution - The non-random survival of random variants.

  • #4
    Senior Coder DanInMa's Avatar
    Join Date
    Nov 2010
    Location
    Salem,Ma
    Posts
    1,577
    Thanks
    13
    Thanked 248 Times in 248 Posts
    I could be wrong but if you are going to use things like : document.getElementById("<%=txtUpn.ClientID %>"); ( which is correct for a .net page)

    I beleive the code has to be on the aspx page itself not in an external js file as the external file doesnt get processed as part of the aspx file

  • #5
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,020
    Thanks
    75
    Thanked 4,323 Times in 4,289 Posts
    Dan is correct on both points.

    Sunfighter: The code shown *IS* correct for ASP.NET pages.

    The reason it must be coded like that is that ASP.NET uses a server-side ID to identify elements that *CAN* occur more than once in a page (in repeating elements). And so then the ASP.NET code automatically generates unique client-side IDs for you. But to access them, you must use the code shown:
    Code:
         serverSideId.clientID
    or
         server-side-reference-to-some-object.clientID
    And then, to dump that into the web page, you must use
    Code:
        <%= serverSideId.clientID %>
    same as you might use
    Code:
        <?php echo something; %>
    with PHP code. Though even PHP, with the proper settings enabled, allows
    Code:
        <?= something ?>
    And so, finally, you need to use
    Code:
        document.getElementById("<%= serverSideId.clientID %>")
    to get the client-side reference to the object.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #6
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,020
    Thanks
    75
    Thanked 4,323 Times in 4,289 Posts
    Pota: It's not the prettiest coding, but what you could do is just create a global variable in your ASP.NET main page and then use it in your ".js" code:
    Code:
    <html>
    <head>
    <script type="text/javascript">
    var txtInUPN = document.getElementById("<%=txtUpn.ClientID %>");
    </script>
    <script type="text/javascript" src="sendMessage.js"></script>
    ...
    </head>
    ...
    And then, in your sendMessage.js code, just use the variable txtInUPN rather than creating and initializing it.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #7
    New to the CF scene
    Join Date
    May 2013
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Old Pedant View Post
    Pota: It's not the prettiest coding, but what you could do is just create a global variable in your ASP.NET main page and then use it in your ".js" code:
    Code:
    <html>
    <head>
    <script type="text/javascript">
    var txtInUPN = document.getElementById("<%=txtUpn.ClientID %>");
    </script>
    <script type="text/javascript" src="sendMessage.js"></script>
    ...
    </head>
    ...
    And then, in your sendMessage.js code, just use the variable txtInUPN rather than creating and initializing it.


    Hello, and thanks for all of your answer guys, but it still dont work. My code now looks like this

    aspx page
    Code:
    <script type="text/jscript">
        var txtInUPN = document.getElementById("<%=txtUpn.ClientID %>");
        var txtOutUPN = document.getElementById("<%= txtUpn.ClientID%>");
    <script>
    sendMessage.js
    Code:
     function mouseInUPN() 
                {
                    
                    txtInUPN.style.background = "#F08080";
    
                    if (txtInUPN.value == '') 
                    {
                        txtInUPN.innerHTML = txtInUPN; 
                        
                    } 
                    else if (txtInUPN.value != '')
                    {
                        mouseOutUPN();
                    }
    
                }
                
                    function mouseOutUPN() 
                {
                    
                    txtOutUPN.style.background = "white";
    
                    if(txtInUPN.value == '')
                    {
                        txtInUPN.innerHTML = txtOutUPN; 
                        
                    }
                    else if (txtInUPN.value != '')
                    {
                        txtOutUPN.style.background = "white";
                    }
                }
    And I still get the error "mouseInUPN" is undefined.

    Got any other idea of whats wrong?

  • #8
    New to the CF scene
    Join Date
    May 2013
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    And or, could it be that it dosent find mouseInUPN from the validate.js file?

  • #9
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,020
    Thanks
    75
    Thanked 4,323 Times in 4,289 Posts
    DEBUG time.

    I don't suppose you can show this in a live URL?
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #10
    New to the CF scene
    Join Date
    May 2013
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hey again,

    Well, when i debug it it redirects me to mouseInUPN(); in validate.js

    validate.js

    Code:
    $(function () {
        $("li.liUPN").mouseenter(function () {
            $this = $(this);
            clearTimeout($this.data("delay1"));
            $this.data("delay1", setTimeout(function () {
                mouseInUPN();
            }, 800)
                           );
        })
    
        $("li.liUPN").mouseleave(function () {
            $this = $(this);
            clearTimeout($this.data("delay1"));
            mouseOutUPN();
        });
    });
    Remember that i have two js files, Validate.js and sendMessage.js which lies under a folder called jscripts.

    Tho when i put all my code from sendMessage.js to Validate.Js it runs without error, BUT the textbox dosent get marked yellow at all. It does nothing.

    I have a similar post here:
    http://forums.asp.net/t/1910021.aspx...N+is+undefined

    But still no luck

    Thanks for all help!

  • #11
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,020
    Thanks
    75
    Thanked 4,323 Times in 4,289 Posts
    That isn't at all what I meant.

    I want you to look at the HTML--*NOT* at the ASP.NET code!--and see what ASP.NET has dumped into the code here:
    Code:
    <script type="text/jscript">
        var txtInUPN = document.getElementById("???");
        var txtOutUPN = document.getElementById("???");
    <script>
    And then put a breakpoint on this line:
    Code:
                    txtInUPN.style.background = "#F08080";
    and see if txtInUPN is indeed the object you expect it to be.

    And and and.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •