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 1 of 1
  1. #1
    Regular Coder
    Join Date
    Jun 2002
    Posts
    905
    Thanks
    23
    Thanked 5 Times in 5 Posts

    Calling a change event function from two places

    Hello,

    I don't javascript/query often so do excuse my poor use of the correct terminology.

    I have a function bound to a form change event which loads some data. It is below...

    Code:
    $("#BrowserGame").bind('change',
    function(){
    $.ajax({async:true, type:'post', complete:
    function(request, json) {
    $('#gamespecifics').html(request.responseText); james() }, url:'/matches/attributes/1/filter', data:$(this).parents('form:first').serialize()
    })
    })
    As you can see from above, when the form field BrowserGame changes value, the function POST's a request and populates the gamespecifics div with what is returned.

    So far so good, the above works. However the function above that makes the POST request and populates the div I also want to run from another function. To simplify...

    CUSTOM FUNCTION()
    {
    CALL ALREADY BINDED FUNCTION FROM ELSEWHERE
    }

    I tried this..

    Code:
    function getResults(){
    $.ajax({async:true, type:'post', complete:
    function(request, json) {
    $('#gamespecifics').html(request.responseText); james() }, url:'/matches/attributes/1/filter', data:$(this).parents('form:first').serialize()
    })
    }
    
    $("#BrowserGame").bind('change',
    getResults()
    )
    customFunction(){
    getResults()
    }
    So as you can see from above, the function that makes the post request and populates my div, I want to be able to call from the change event but also other places. It fails. I'm guessing it is because the function is refering to the form as this however I need to specifiy the actual form I'm referring to as I'm calling it from elsewhere?

    Any thoughts?

    Many thanks
    Sir P


 

Posting Permissions

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