jQuery & Functions
|
View:
New views
3 Messages
—
Rating Filter:
Alert me
|
|
|
jQuery & FunctionsFirstly hello everyone and apologies for breaking new ground in terms
of simple idiot questions. Ok so I'm trouble doing something I would consider as simple with jquery. I have a form and i want to run a common function (that checks a bunch of inputs) that will be run when certain fields blur. working off the blur field is not a problem, but parsing the function is... example below. Looking at callback's in jQuery I'm still a bit confused and i cannot find anything floating around the net that does similar to what i want to do (common function invoked from multiple different fields). function EvalFields() { var arrFieldNames = array; var boolFields = boolean; boolFields = true; alert("running"); // easy way to know if your running the code or not arrFieldNames[0] = "#frmField1"; arrFieldNames[1] = "#frmField2"; arrFieldNames[2] = "#frmField3"; arrFieldNames[3] = "#frmField4"; arrFieldNames[4] = "#frmField5"; for (var x=0;x>arrFieldNames.length;x++) { if( !$.(arrFieldNames[x]).empty() ){ boolFields = false; } } if (boolFields == true) { $.("#frmHiddenField").val("1"); } else { $.("#frmHiddenField").val("0"); } } ^^ this is the function I want to use. It just cycles through a bunch of fields and if they all have content it'll flick a switch for server side processing later on. $("#frmField1").blur(function () { EvalFields(); }); $("#frmField2").blur(function () { EvalFields(); }); $("#frmField3").blur(function () { EvalFields(); }); $("#frmField4").blur(function () { EvalFields(); }); $("#frmField5").blur(function () { EvalFields(); }); ^^ the on blur events should be fine right? I'm assuming that I'm not defining the function properly and/or passing jquery through(maybe i'm not event getting this far!)... The whole point of this was to not write the exact same code for the 5 odd, specific, blur events but i've wasted so much time on this i need to seek assistance. Can anyone help me with this? Thanks in advance. p.s. all form elements have appropriate id's set, etc. and I'm successfully using the Validation plugin already. |
|
|
Re: jQuery & FunctionsWhat is this syntax supposed to accomplish?
if( !$.(arrFieldNames[x]).empty() ){ Issues: "empty()" is a *method* and it empties the children from a DOM object (see the docs: http://docs.jquery.com/Manipulation/empty) You've also got a period after the $, that's not good (nor going to work!) On Nov 10, 7:56 pm, Digital Evasion <digital.evas...@...> wrote: > Firstly hello everyone and apologies for breaking new ground in terms > of simple idiot questions. > Ok so I'm trouble doing something I would consider as simple with > jquery. > I have a form and i want to run a common function (that checks a bunch > of inputs) that will be run when certain fields blur. working off the > blur field is not a problem, but parsing the function is... example > below. Looking at callback's in jQuery I'm still a bit confused and i > cannot find anything floating around the net that does similar to what > i want to do (common function invoked from multiple different fields). > > function EvalFields() { > var arrFieldNames = array; > var boolFields = boolean; > boolFields = true; > alert("running"); // easy way to know if your running the code > or not > arrFieldNames[0] = "#frmField1"; > arrFieldNames[1] = "#frmField2"; > arrFieldNames[2] = "#frmField3"; > arrFieldNames[3] = "#frmField4"; > arrFieldNames[4] = "#frmField5"; > for (var x=0;x>arrFieldNames.length;x++) { > if( !$.(arrFieldNames[x]).empty() ){ > boolFields = false; > } > } > if (boolFields == true) { > $.("#frmHiddenField").val("1"); > } else { > $.("#frmHiddenField").val("0"); > } > } > > ^^ this is the function I want to use. It just cycles through a bunch > of fields and if they all have content it'll flick a switch for server > side processing later on. > > $("#frmField1").blur(function () { > EvalFields(); > }); > $("#frmField2").blur(function () { > EvalFields(); > }); > $("#frmField3").blur(function () { > EvalFields(); > }); > $("#frmField4").blur(function () { > EvalFields(); > }); > $("#frmField5").blur(function () { > EvalFields(); > }); > ^^ the on blur events should be fine right? > > I'm assuming that I'm not defining the function properly and/or > passing jquery through(maybe i'm not event getting this far!)... > > The whole point of this was to not write the exact same code for the 5 > odd, specific, blur events but i've wasted so much time on this i need > to seek assistance. > > Can anyone help me with this? Thanks in advance. > > p.s. all form elements have appropriate id's set, etc. and I'm > successfully using the Validation plugin already. |
|
|
Re: jQuery & FunctionsHi MorningZ,
thanks for your help it is greatly appreciated. Yes i did get a bit confused with empty (i blame php :P). I've only been playing with jquery or anything besides plain old document.form.elementname JS for a week so i'm all over the palce. I now have it all working just fine. final code for any who are interrested is: function EvalSecondContact() { var arrSCFieldNames=new Array(); var boolSCFields = new Boolean; boolSCFields = true; alert("running"); // easy to test arrSCFieldNames[0] = "#frmSC_Street_Address_1"; arrSCFieldNames[1] = "#frmSC_Street_Address_2"; arrSCFieldNames[2] = "#frmSC_Street_Suburb"; arrSCFieldNames[3] = "#frmSC_Street_State"; arrSCFieldNames[4] = "#frmSC_Street_Postcode"; for (var x=0;x<arrSCFieldNames.length;x++) { if( $(arrSCFieldNames[x]).val().length<1 ){ boolSCFields = false; } } if (boolSCFields == true) { $("#frmUseSecondaryInfo").val("1"); } else { $("#frmUseSecondaryInfo").val("0"); } } // }); // end function $("#frmSC_Street_Address_1").blur(function () { EvalSecondContact(); }); $("#frmSC_Street_Address_2").blur(function () { EvalSecondContact(); }); $("#frmSC_Street_Suburb").blur(function () { EvalSecondContact(); }); $("#frmSC_Street_State").blur(function () { EvalSecondContact(); }); $("#frmSC_Street_Postcode").blur(function () { EvalSecondContact(); }); On Nov 11, 12:29 pm, MorningZ <morni...@...> wrote: > What is this syntax supposed to accomplish? > > if( !$.(arrFieldNames[x]).empty() ){ > > Issues: "empty()" is a *method* and it empties the children from a > DOM object (see the docs:http://docs.jquery.com/Manipulation/empty) > > You've also got a period after the $, that's not good (nor going to > work!) > > On Nov 10, 7:56 pm, Digital Evasion <digital.evas...@...> wrote: > > > Firstly hello everyone and apologies for breaking new ground in terms > > of simple idiot questions. > > Ok so I'm trouble doing something I would consider as simple with > > jquery. > > I have a form and i want to run a common function (that checks a bunch > > of inputs) that will be run when certain fields blur. working off the > > blur field is not a problem, but parsing the function is... example > > below. Looking at callback's in jQuery I'm still a bit confused and i > > cannot find anything floating around the net that does similar to what > > i want to do (common function invoked from multiple different fields). > > > function EvalFields() { > > var arrFieldNames = array; > > var boolFields = boolean; > > boolFields = true; > > alert("running"); // easy way to know if your running the code > > or not > > arrFieldNames[0] = "#frmField1"; > > arrFieldNames[1] = "#frmField2"; > > arrFieldNames[2] = "#frmField3"; > > arrFieldNames[3] = "#frmField4"; > > arrFieldNames[4] = "#frmField5"; > > for (var x=0;x>arrFieldNames.length;x++) { > > if( !$.(arrFieldNames[x]).empty() ){ > > boolFields = false; > > } > > } > > if (boolFields == true) { > > $.("#frmHiddenField").val("1"); > > } else { > > $.("#frmHiddenField").val("0"); > > } > > } > > > ^^ this is the function I want to use. It just cycles through a bunch > > of fields and if they all have content it'll flick a switch for server > > side processing later on. > > > $("#frmField1").blur(function () { > > EvalFields(); > > }); > > $("#frmField2").blur(function () { > > EvalFields(); > > }); > > $("#frmField3").blur(function () { > > EvalFields(); > > }); > > $("#frmField4").blur(function () { > > EvalFields(); > > }); > > $("#frmField5").blur(function () { > > EvalFields(); > > }); > > ^^ the on blur events should be fine right? > > > I'm assuming that I'm not defining the function properly and/or > > passing jquery through(maybe i'm not event getting this far!)... > > > The whole point of this was to not write the exact same code for the 5 > > odd, specific, blur events but i've wasted so much time on this i need > > to seek assistance. > > > Can anyone help me with this? Thanks in advance. > > > p.s. all form elements have appropriate id's set, etc. and I'm > > successfully using the Validation plugin already. |
| Free embeddable forum powered by Nabble | Forum Help |