Issues with converting to a function

Discussion in 'JavaScript' started by rockinaway, Aug 11, 2011.

  1. #1
    I'm having a bit of an issue converting a piece of code into a function. My issue can be described here: http://www.phpfreaks.com/forums/index.php?topic=341166.0

    The code I have used is also there.

    Basically, when the code is not in a function it works fine. As soon as I convert it into a function (as described by the members at PHPfreaks) it doesn't work. I am not sure what is going wrong.

    Any help will be nice thanks
     
    rockinaway, Aug 11, 2011 IP
  2. JohnnySchultz

    JohnnySchultz Peon

    Messages:
    277
    Likes Received:
    4
    Best Answers:
    7
    Trophy Points:
    0
    #2
    can you post your version of the code here so we can inspect what might be the cause of it?
     
    JohnnySchultz, Aug 16, 2011 IP
  3. waiidigitalpoint

    waiidigitalpoint Peon

    Messages:
    1
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    looking at that thread, what nogray suggested should have worked assuming you have other helper functions all defined. why don't you post the complete code here or host it somewhere for us to debug.
     
    waiidigitalpoint, Aug 16, 2011 IP
  4. ModulesGarden

    ModulesGarden Active Member

    Messages:
    21
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    58
    #4
    I think you've messed this since you are using "this" parameter.
    Try this one:

    1. Change function - use "elem" instead of "this".Change it in whole function
    
    function check_user(elem) {
        // .... change all "this" to "elem"
    
    }
    
    Code (markup):
    2. Call the function with this code:
     
        $('#username').keyup(function () { check_user(this);}); 
    Code (markup):
    You can also try to change the function name, maybe it is already declared.
    Let me know if it helped you.
     
    ModulesGarden, Aug 16, 2011 IP