Hi guys, Been working on this most of the day and not getting anywhere fast. I am working on a simple e-commerce system more specifically a filter system for product listings. What I have at present is two sets of radio buttons which are generated by my productFilters() javascript function, which in turn runs an Ajax.Updater, as the page loads: Set 1: Option 1, Option 2, Option 3 Set 2: Option A, Option B, Option c Each radio button has an onChange event in place which recalls the productFilters() function. The function first creates an array including the value of each set of radio buttons. This is where I am stuck ... how do I pass my variable through to PHP in the following format? filters[set1] = value filters[set2] = value I am creating this array in the javascript no probem, but cannot post it to the PHP script. Here is my javascript function. function productFilters(params) { var filters = new Array(); $$(''#productFiltersWrap input[type="radio"]'').pluck(''name'').uniq().each(function(f) { filters[f] = $$(''input:checked[type="radio"][name="'' + f + ''"]'').pluck(''value''); }); if (!params.evalScripts) { params.evalScripts = false; } new Ajax.Updater(params.container, ''/js/ajax.php'', { parameters: Object.extend ({filters: filters}, params), evalScripts: params.evalScripts}); } --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
What do you mean by "cannot post to the PHP script"? Does it come in a wrong format? - kangax On May 31, 12:10 pm, WebbedIT <p...-BKqkkOijtfm9FHfhHBbuYA@public.gmane.org> wrote:> Hi guys, > > Been working on this most of the day and not getting anywhere fast. I > am working on a simple e-commerce system more specifically a filter > system for product listings. > > What I have at present is two sets of radio buttons which are > generated by my productFilters() javascript function, which in turn > runs an Ajax.Updater, as the page loads: > > Set 1: Option 1, Option 2, Option 3 > Set 2: Option A, Option B, Option c > > Each radio button has an onChange event in place which recalls the > productFilters() function. The function first creates an array > including the value of each set of radio buttons. This is where I am > stuck ... how do I pass my variable through to PHP in the following > format? > > filters[set1] = value > filters[set2] = value > > I am creating this array in the javascript no probem, but cannot post > it to the PHP script. Here is my javascript function. > > function productFilters(params) { > var filters = new Array(); > $$(''#productFiltersWrap > input[type="radio"]'').pluck(''name'').uniq().each(function(f) { > filters[f] = $$(''input:checked[type="radio"][name="'' + f + > ''"]'').pluck(''value''); > }); > if (!params.evalScripts) { > params.evalScripts = false; > } > new Ajax.Updater(params.container, ''/js/ajax.php'', { parameters: > Object.extend ({filters: filters}, params), evalScripts: > params.evalScripts}); > > }--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
The array wouldn''t go at all where it should have posted filters=arrayString¶msVar1=Value1¶msVar2=value2 it just kept posting ¶msVar1=Value1¶msVar2=value2 I have now experimented further and have created a hash which I then passed through toJson() before posting to PHP where I used json_decode(). So whilst the initial issue is not resolved (it probably can''t be as I don''t think you can pass through an associative array) I have managed to get my code working. Thanks, Paul. On May 31, 7:02 pm, kangax <kan...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> What do you mean by "cannot post to the PHP script"? > Does it come in a wrong format? > > - kangax > > On May 31, 12:10 pm, WebbedIT <p...-BKqkkOijtfm9FHfhHBbuYA@public.gmane.org> wrote: > > > Hi guys, > > > Been working on this most of the day and not getting anywhere fast. I > > am working on a simple e-commerce system more specifically a filter > > system for product listings. > > > What I have at present is two sets of radio buttons which are > > generated by my productFilters() javascript function, which in turn > > runs an Ajax.Updater, as the page loads: > > > Set 1: Option 1, Option 2, Option 3 > > Set 2: Option A, Option B, Option c > > > Each radio button has an onChange event in place which recalls the > > productFilters() function. The function first creates an array > > including the value of each set of radio buttons. This is where I am > > stuck ... how do I pass my variable through to PHP in the following > > format? > > > filters[set1] = value > > filters[set2] = value > > > I am creating this array in the javascript no probem, but cannot post > > it to the PHP script. Here is my javascript function. > > > function productFilters(params) { > > var filters = new Array(); > > $$(''#productFiltersWrap > > input[type="radio"]'').pluck(''name'').uniq().each(function(f) { > > filters[f] = $$(''input:checked[type="radio"][name="'' + f + > > ''"]'').pluck(''value''); > > }); > > if (!params.evalScripts) { > > params.evalScripts = false; > > } > > new Ajax.Updater(params.container, ''/js/ajax.php'', { parameters: > > Object.extend ({filters: filters}, params), evalScripts: > > params.evalScripts}); > > > }--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
Paul, you can certainly pass anything that could be represented as a string. It''s just a matter of *how* to represent it. Object.toQueryString does indeed skip object properties. Transforming those properties into an array before sending request shouldn''t be too hard though. - kangax On May 31, 2:11 pm, WebbedIT <p...-BKqkkOijtfm9FHfhHBbuYA@public.gmane.org> wrote:> The array wouldn''t go at all where it should have posted > > filters=arrayString¶msVar1=Value1¶msVar2=value2 > > it just kept posting > > ¶msVar1=Value1¶msVar2=value2 > > I have now experimented further and have created a hash which I then > passed through toJson() before posting to PHP where I used > json_decode(). So whilst the initial issue is not resolved (it > probably can''t be as I don''t think you can pass through an associative > array) I have managed to get my code working. > > Thanks, > > Paul. > > On May 31, 7:02 pm, kangax <kan...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > What do you mean by "cannot post to the PHP script"? > > Does it come in a wrong format? > > > - kangax > > > On May 31, 12:10 pm, WebbedIT <p...-BKqkkOijtfm9FHfhHBbuYA@public.gmane.org> wrote: > > > > Hi guys, > > > > Been working on this most of the day and not getting anywhere fast. I > > > am working on a simple e-commerce system more specifically a filter > > > system for product listings. > > > > What I have at present is two sets of radio buttons which are > > > generated by my productFilters() javascript function, which in turn > > > runs an Ajax.Updater, as the page loads: > > > > Set 1: Option 1, Option 2, Option 3 > > > Set 2: Option A, Option B, Option c > > > > Each radio button has an onChange event in place which recalls the > > > productFilters() function. The function first creates an array > > > including the value of each set of radio buttons. This is where I am > > > stuck ... how do I pass my variable through to PHP in the following > > > format? > > > > filters[set1] = value > > > filters[set2] = value > > > > I am creating this array in the javascript no probem, but cannot post > > > it to the PHP script. Here is my javascript function. > > > > function productFilters(params) { > > > var filters = new Array(); > > > $$(''#productFiltersWrap > > > input[type="radio"]'').pluck(''name'').uniq().each(function(f) { > > > filters[f] = $$(''input:checked[type="radio"][name="'' + f + > > > ''"]'').pluck(''value''); > > > }); > > > if (!params.evalScripts) { > > > params.evalScripts = false; > > > } > > > new Ajax.Updater(params.container, ''/js/ajax.php'', { parameters: > > > Object.extend ({filters: filters}, params), evalScripts: > > > params.evalScripts}); > > > > }--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---