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 6 of 6
  1. #1
    New Coder
    Join Date
    Mar 2013
    Posts
    80
    Thanks
    45
    Thanked 0 Times in 0 Posts

    need javascript help [1]

    <input placeholder="Password.." onfocus="y()" type="text"/>


    function y(){
    this.style.backgroundColor="red";
    }
    whys this not working, can someone help?
    Last edited by h123er2; 11-19-2013 at 11:12 PM.

  • #2
    The fat guy next door VIPStephan's Avatar
    Join Date
    Jan 2006
    Location
    Halle (Saale), Germany
    Posts
    8,624
    Thanks
    6
    Thanked 1,001 Times in 974 Posts
    There is no way to tell you without seeing any context.

  • #3
    New Coder
    Join Date
    Mar 2013
    Posts
    80
    Thanks
    45
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by VIPStephan View Post
    There is no way to tell you without seeing any context.
    sorry mate, just updated it.

  • #4
    New Coder
    Join Date
    Sep 2010
    Location
    U S of A
    Posts
    56
    Thanks
    0
    Thanked 12 Times in 12 Posts
    Code:
    <!DOCTYPE html>
    <html>
    <head>
     <title></title>
     <meta charset="utf-8" > 
    </head>
    <body>
    <input placeholder="Password.." onfocus="y.call(this)" type="text"/>
    
    <script>
    function y(){
     this.style.backgroundColor="red";
    }
     
    </script>
    </body>
    </html>

  • Users who have thanked Shaka Zorba for this post:

    h123er2 (11-19-2013)

  • #5
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,616
    Thanks
    0
    Thanked 645 Times in 635 Posts
    Just y(this) should be sufficient - there's no need to use call in this instance.
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

  • #6
    Regular Coder
    Join Date
    Aug 2010
    Posts
    966
    Thanks
    19
    Thanked 211 Times in 209 Posts
    Quote Originally Posted by felgall View Post
    Just y(this) should be sufficient - there's no need to use call in this instance.
    yes but only if you change
    the function also ...

    Code:
     
     <!DOCTYPE html>
    <html>
    <head>
     <title></title>
     <meta charset="utf-8" > 
    </head>
    <body>
    <input placeholder="Password.." onfocus="y(this)" type="text"/>
     <script>
    function y(el){
     el.style.backgroundColor="red";
    }
     
    </script>
    </body>
    </html>


  •  

    Posting Permissions

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