[jQuery] Passing values to a custom function
Hi again,
following up my previous post where I was trying to bind a function to a submit event, I'm now trying to pass values from the function that returns a function to the bound submit event.<br clear="all">
I've a number of forms on a page, that perform a variety of functions, some similar. I'm trying to create a custom function that posts a checkbox variable, but within the context of the function that returns a function, I can't pass the variables across.
If I put an alert(formName); etc, in the postCheckbox function, it confirms the values are being passed across, but alert(document.formName.tagName); , for example, gives 'undefined'.
Why does the function not abstract out in this case?
Many thanks,
Dan.
$(document).ready(function(){
initialiseForm("#PollX");
initialiseForm("#PollY");
initialiseForm("#RateX");
});
function initialiseForm(formId) {
$(formId).bind('submit', getPost(formId));
}
function getPost(formId) {
return function() {
switch(formId){
case "#PollX":
postCheckbox("PollX", "PollXGroup", "div#PollXDiv", "
PollXresults.php?PollXRadio=")
return false;
break;
case "#PollY":
//do something else
return false;
break;
case "#RateX":
// do more things
postCheckbox("RateX", "RateXGroup", "div#RateXDiv", "RateXresults.php?RateXRadio=")
return false;
break;
default:
return false;
}
};
}
function postCheckbox(formName, radioGroupName, replacementBlock, postURL){
for (var i=0; i < document.formName.radioGroupName.length; i++) {
if (document.formName.radioGroupName[i].checked){
var radioValue = document.formName.radioGroupName[i].value;
}
}
if(radioValue){
$(replacementBlock).load(postURL + radioValue).fadeIn("slow");
}
}
--
Daniel Eastwell
Portfolio and articles:
<a href="http://www.thoughtballoon.co.uk">
http://www.thoughtballoon.co.uk</a>
Blog:
<a href="http://www.thoughtballoon.co.uk/blog">http://www.thoughtballoon.co.uk/blog</a>
_______________________________________________
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/