[jQuery] Passing values to a custom function
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=us-ascii">
<META content="MSHTML 6.00.5730.11" name=GENERATOR></HEAD>
<BODY>
<DIV dir=ltr align=left><SPAN class=296165419-08012007><FONT face=Verdana
color=#0000ff size=2>Do you want getPost to be called during the execution of
initialiseForm, or later in response to the 'submit' event? For the
latter, use this (added code in <FONT
color=#ff0000>red</FONT>):</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=296165419-08012007><FONT face=Verdana
color=#0000ff size=2></FONT></SPAN> </DIV>
<DIV dir=ltr align=left><SPAN class=296165419-08012007><FONT face=Verdana
color=#0000ff size=2><FONT face="Times New Roman" color=#000000 size=3>function
initialiseForm(formId) { <BR> $(formId).bind('submit',
<FONT color=#ff0000>function() {</FONT> getPost(formId) <FONT
color=#ff0000>}</FONT> );<BR>}</FONT><BR></FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=296165419-08012007><FONT face=Verdana
color=#0000ff size=2>-Mike</FONT></SPAN></DIV><BR>
<BLOCKQUOTE
style="PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #0000ff 2px solid; MARGIN-RIGHT: 0px">
<DIV class=OutlookMessageHeader lang=en-us dir=ltr align=left>
<HR tabIndex=-1>
<FONT face=Tahoma size=2><B>From:</B> discuss-bounces@jquery.com
[mailto:discuss-bounces@jquery.com] <B>On Behalf Of </B>Dan
Eastwell<BR><B>Sent:</B> Monday, January 08, 2007 4:24 AM<BR><B>To:</B> jQuery
Discussion.<BR><B>Subject:</B> [jQuery] Passing values to a custom
function<BR></FONT><BR></DIV>
<DIV></DIV>Hi again,<BR><BR>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><BR>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. <BR><BR>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'. <BR><BR>Why does the function not abstract out in this
case? <BR><BR>Many
thanks,<BR><BR>Dan.<BR><BR>$(document).ready(function(){<BR>
initialiseForm("#PollX");<BR>
initialiseForm("#PollY");<BR>
initialiseForm("#RateX");<BR>});<BR><BR>function initialiseForm(formId) {
<BR> $(formId).bind('submit',
getPost(formId));<BR>}<BR><BR>function getPost(formId)
{<BR> return function()
{<BR>
switch(formId){<BR>
case "#PollX":<BR>
postCheckbox("PollX", "PollXGroup", "div#PollXDiv", "
PollXresults.php?PollXRadio=")<BR>
return false;<BR>
break;<BR>
case "#PollY":<BR>
//do something
else<BR>
return false;<BR>
break; <BR>
case
"#RateX":<BR>
// do more things<BR>
postCheckbox("RateX", "RateXGroup", "div#RateXDiv",
"RateXresults.php?RateXRadio=")<BR>
return false;<BR>
break;<BR>
default:<BR>
return
false;<BR>
} <BR> };<BR>}<BR><BR>function
postCheckbox(formName, radioGroupName, replacementBlock, postURL){
<BR> for (var i=0; i <
document.formName.radioGroupName.length; i++) {<BR>
if
(document.formName.radioGroupName[i].checked){<BR>
var radioValue =
document.formName.radioGroupName[i].value;<BR>
} <BR> }<BR>
if(radioValue){ <BR>
$(replacementBlock).load(postURL +
radioValue).fadeIn("slow");<BR> }<BR>}<BR><BR><BR>--
<BR>Daniel Eastwell<BR><BR>Portfolio and articles:<BR><A
href="http://www.thoughtballoon.co.uk">http://www.thoughtballoon.co.uk</A><BR><BR>Blog:<BR><A
href="http://www.thoughtballoon.co.uk/blog">http://www.thoughtballoon.co.uk/blog</A>
</BLOCKQUOTE></BODY></HTML>
_______________________________________________
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/