...

View Full Version : jQuery Calling a change event function from two places



sir pannels
11-20-2010, 11:39 AM
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...



$("#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..



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 :D



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum