I am trying to write some code using javascript and the prototype library that makes sure certain divs are contained in a column div, if they are not they get moved there. I''m getting the error "$(w_id) has no properties" when I run it. Is it possible to programmatically build a string containing a div id then use it like I need to? I''m new to prototype. Thanks in advance. Here is my code snippet: var x; var w_id = ""; //step through the first column for( x in col0 ) { w_id = ''w_'' + col0[x]; //if the current item is not in col0, move it there if( ! ($(w_id).descendantOf(''col-0'')) ) { $(''col-0'').insert(document.getElementById(w_id)); } } --~--~---------~--~----~------------~-------~--~----~ 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 is the contents of your "col0" variable? If it''s an array you should not use the "for (x in ...)" loop but a traditional for (x = 0; x < y; x++) loop or Prototype''s Array#each If you post how you get the col0''s contents setup I''m sure we can help you. 2008/5/8 Timebomb <twelbourn-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>:> > I am trying to write some code using javascript and the prototype > library that makes sure certain divs are contained in a column div, if > they are not they get moved there. I''m getting the error "$(w_id) has > no properties" when I run it. Is it possible to programmatically build > a string containing a div id then use it like I need to? I''m new to > prototype. Thanks in advance. > > Here is my code snippet: > > var x; > var w_id = ""; > > //step through the first column > for( x in col0 ) { > w_id = ''w_'' + col0[x]; > > //if the current item is not in col0, move it there > if( ! ($(w_id).descendantOf(''col-0'')) ) { > $(''col-0'').insert(document.getElementById(w_id)); > } > > } > > >-- burnfield.com/martin --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Thanks for the reply Martin! col0 is an array of integers that retrieved from a browser cookie. The page I am working on is similar to the iGoogle page where you have movable widgets arranged in 3 columns. Widgets can be moved up and down in their column and even between columns. I''m primarily using the Scriptaculous Sortables class to make columns sortable with each other. Column order is saved and restored via the Sequence and setSequence function calls and cookies. That part was straight forward. However, I need a method to move the widgets to the correct column div before calling setSequence. Right now the code is repetitive, but it''s just a first draft. :) Here is the full function: Columns are divs with id''s of "col-0", "col-1", and "col-2" Widget are divs with id''s like "w_2" and "w_20" and are contained in columns There is one cookie per column that contains a list of integers separated by commas, the integers correspond to the order the widgets should appear in the column. function orderWidgetsByColumn() { //these are string containing integers separated by commas //example: 2,18,3,19,3 var widgetListStr0 = getCookie(''col-0''); var widgetListStr1 = getCookie(''col-1''); var widgetListStr2 = getCookie(''col-2''); //if all cookies are set, move all widgets to the correct column if( widgetListStr0.length > 0 && widgetListStr1.length > 0 && widgetListStr2.length > 0 ) { //convert the comma delimited strings to arrays var col0 = widgetListStr0.split('',''); var col1 = widgetListStr1.split('',''); var col2 = widgetListStr2.split('',''); var x; var w_id = ""; //step through the first column for( x in col0 ) { w_id = ''w_'' + col0[x]; //if the current item is not in col0, move it there if( ! ($(w_id).descendantOf(''col-0'')) ) { $(''col-0'').insert(document.getElementById(w_id)); } } //step through the second column for( x in col1 ) { w_id = "w_" + col0[x]; //if the current item is not in col0, move it there if( ! ($(w_id).descendantOf(''col-1'')) ) { $(''col-1'').insert(document.getElementById(w_id)); } } //step through the third column for( x in col2 ) { w_id = "w_" + col0[x]; //if the current item is not in col2, move it there if( ! ($(w_id).descendantOf(''col-2'')) ) { $(''col-2'').insert(document.getElementById(w_id)); } } } return; } On May 8, 5:20 am, "Martin Ström" <martinstromli...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> What is the contents of your "col0" variable? > If it''s an array you should not use the "for (x in ...)" loop but a > traditional for (x = 0; x < y; x++) loop or Prototype''s Array#each > > If you post how you get the col0''s contents setup I''m sure we can help you. > > 2008/5/8 Timebomb <twelbo...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>: > > > > > > > I am trying to write some code using javascript and the prototype > > library that makes sure certain divs are contained in a column div, if > > they are not they get moved there. I''m getting the error "$(w_id) has > > no properties" when I run it. Is it possible to programmatically build > > a string containing a div id then use it like I need to? I''m new to > > prototype. Thanks in advance. > > > Here is my code snippet: > > > var x; > > var w_id = ""; > > > //step through the first column > > for( x in col0 ) { > > w_id = ''w_'' + col0[x]; > > > //if the current item is not in col0, move it there > > if( ! ($(w_id).descendantOf(''col-0'')) ) { > > $(''col-0'').insert(document.getElementById(w_id)); > > } > > > } > > -- > burnfield.com/martin--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Looking over it, I already see that I forgot to update lines that read: "w_id = "w_" + col0[x];" in each column loop. But that''s not where I''m getting the javascript error. Tim On May 8, 7:49 am, Timebomb <twelbo...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Thanks for the reply Martin! col0 is an array of integers that > retrieved from a browser cookie. The page I am working on is similar > to the iGoogle page where you have movable widgets arranged in 3 > columns. Widgets can be moved up and down in their column and even > between columns. I''m primarily using the Scriptaculous Sortables class > to make columns sortable with each other. Column order is saved and > restored via the Sequence and setSequence function calls and cookies. > That part was straight forward. However, I need a method to move the > widgets to the correct column div before calling setSequence. Right > now the code is repetitive, but it''s just a first draft. :) Here is > the full function: > > Columns are divs with id''s of "col-0", "col-1", and "col-2" > Widget are divs with id''s like "w_2" and "w_20" and are contained in > columns > There is one cookie per column that contains a list of integers > separated by commas, the integers correspond to the order the widgets > should appear in the column. > > function orderWidgetsByColumn() { > //these are string containing integers separated by commas > //example: 2,18,3,19,3 > var widgetListStr0 = getCookie(''col-0''); > var widgetListStr1 = getCookie(''col-1''); > var widgetListStr2 = getCookie(''col-2''); > > //if all cookies are set, move all widgets to the correct column > if( widgetListStr0.length > 0 && > widgetListStr1.length > 0 && > widgetListStr2.length > 0 ) { > > //convert the comma delimited strings to arrays > var col0 = widgetListStr0.split('',''); > var col1 = widgetListStr1.split('',''); > var col2 = widgetListStr2.split('',''); > > var x; > var w_id = ""; > > //step through the first column > for( x in col0 ) { > w_id = ''w_'' + col0[x]; > > //if the current item is not in col0, move it there > if( ! ($(w_id).descendantOf(''col-0'')) ) { > $(''col-0'').insert(document.getElementById(w_id)); > } > > } > > //step through the second column > for( x in col1 ) { > w_id = "w_" + col0[x]; > > //if the current item is not in col0, move it there > if( ! ($(w_id).descendantOf(''col-1'')) ) { > $(''col-1'').insert(document.getElementById(w_id)); > } > } > > //step through the third column > for( x in col2 ) { > w_id = "w_" + col0[x]; > > //if the current item is not in col2, move it there > if( ! ($(w_id).descendantOf(''col-2'')) ) { > $(''col-2'').insert(document.getElementById(w_id)); > } > } > > } > > return; > > } > > On May 8, 5:20 am, "Martin Ström" <martinstromli...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > What is the contents of your "col0" variable? > > If it''s an array you should not use the "for (x in ...)" loop but a > > traditional for (x = 0; x < y; x++) loop or Prototype''s Array#each > > > If you post how you get the col0''s contents setup I''m sure we can help you. > > > 2008/5/8 Timebomb <twelbo...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>: > > > > I am trying to write some code using javascript and the prototype > > > library that makes sure certain divs are contained in a column div, if > > > they are not they get moved there. I''m getting the error "$(w_id) has > > > no properties" when I run it. Is it possible to programmatically build > > > a string containing a div id then use it like I need to? I''m new to > > > prototype. Thanks in advance. > > > > Here is my code snippet: > > > > var x; > > > var w_id = ""; > > > > //step through the first column > > > for( x in col0 ) { > > > w_id = ''w_'' + col0[x]; > > > > //if the current item is not in col0, move it there > > > if( ! ($(w_id).descendantOf(''col-0'')) ) { > > > $(''col-0'').insert(document.getElementById(w_id)); > > > } > > > > } > > > -- > > burnfield.com/martin--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
And I think the root of my problem is that code like this works: $(''col-2'').insert(document.getElementById(''w_18'')); But this doesn''t work: var col = "col-2"; $(col).insert(document.getElementById(''w_18'')); How would I get around this? I want to reference elements by strings that are built programmatically, not hard coded. Tim On May 8, 7:49 am, Timebomb <twelbo...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Thanks for the reply Martin! col0 is an array of integers that > retrieved from a browser cookie. The page I am working on is similar > to the iGoogle page where you have movable widgets arranged in 3 > columns. Widgets can be moved up and down in their column and even > between columns. I''m primarily using the Scriptaculous Sortables class > to make columns sortable with each other. Column order is saved and > restored via the Sequence and setSequence function calls and cookies. > That part was straight forward. However, I need a method to move the > widgets to the correct column div before calling setSequence. Right > now the code is repetitive, but it''s just a first draft. :) Here is > the full function: > > Columns are divs with id''s of "col-0", "col-1", and "col-2" > Widget are divs with id''s like "w_2" and "w_20" and are contained in > columns > There is one cookie per column that contains a list of integers > separated by commas, the integers correspond to the order the widgets > should appear in the column. > > function orderWidgetsByColumn() { > //these are string containing integers separated by commas > //example: 2,18,3,19,3 > var widgetListStr0 = getCookie(''col-0''); > var widgetListStr1 = getCookie(''col-1''); > var widgetListStr2 = getCookie(''col-2''); > > //if all cookies are set, move all widgets to the correct column > if( widgetListStr0.length > 0 && > widgetListStr1.length > 0 && > widgetListStr2.length > 0 ) { > > //convert the comma delimited strings to arrays > var col0 = widgetListStr0.split('',''); > var col1 = widgetListStr1.split('',''); > var col2 = widgetListStr2.split('',''); > > var x; > var w_id = ""; > > //step through the first column > for( x in col0 ) { > w_id = ''w_'' + col0[x]; > > //if the current item is not in col0, move it there > if( ! ($(w_id).descendantOf(''col-0'')) ) { > $(''col-0'').insert(document.getElementById(w_id)); > } > > } > > //step through the second column > for( x in col1 ) { > w_id = "w_" + col0[x]; > > //if the current item is not in col0, move it there > if( ! ($(w_id).descendantOf(''col-1'')) ) { > $(''col-1'').insert(document.getElementById(w_id)); > } > } > > //step through the third column > for( x in col2 ) { > w_id = "w_" + col0[x]; > > //if the current item is not in col2, move it there > if( ! ($(w_id).descendantOf(''col-2'')) ) { > $(''col-2'').insert(document.getElementById(w_id)); > } > } > > } > > return; > > } > > On May 8, 5:20 am, "Martin Ström" <martinstromli...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > What is the contents of your "col0" variable? > > If it''s an array you should not use the "for (x in ...)" loop but a > > traditional for (x = 0; x < y; x++) loop or Prototype''s Array#each > > > If you post how you get the col0''s contents setup I''m sure we can help you. > > > 2008/5/8 Timebomb <twelbo...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>: > > > > I am trying to write some code using javascript and the prototype > > > library that makes sure certain divs are contained in a column div, if > > > they are not they get moved there. I''m getting the error "$(w_id) has > > > no properties" when I run it. Is it possible to programmatically build > > > a string containing a div id then use it like I need to? I''m new to > > > prototype. Thanks in advance. > > > > Here is my code snippet: > > > > var x; > > > var w_id = ""; > > > > //step through the first column > > > for( x in col0 ) { > > > w_id = ''w_'' + col0[x]; > > > > //if the current item is not in col0, move it there > > > if( ! ($(w_id).descendantOf(''col-0'')) ) { > > > $(''col-0'').insert(document.getElementById(w_id)); > > > } > > > > } > > > -- > > burnfield.com/martin--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Wait wait, crisis averted.... Martin, I implemented your suggestion and it''s now working! I modeled that loop on the following examples from w3schools.com. I wonder why it didn''t work? http://www.w3schools.com/js/js_obj_array.asp http://www.w3schools.com/js/tryit.asp?filename=tryjs_array_for_in Thank you soooo much for your help! Here''s an example of the change: //step through the first column for( x=x; x<col0.length; ++x ) { w_id = ''w_'' + col0[x]; //if the current item is not in col-0, move it there if( ! ($ (w_id).descendantOf(''col-0'')) ) { $ (''col-0'').insert(document.getElementById(w_id)); } } Have a great day! Tim On May 8, 7:54 am, Timebomb <twelbo...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Looking over it, I already see that I forgot to update lines that > read: "w_id = "w_" + col0[x];" in each column loop. But that''s not > where I''m getting the javascript error. > > Tim > > On May 8, 7:49 am, Timebomb <twelbo...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > Thanks for the reply Martin! col0 is an array of integers that > > retrieved from a browser cookie. The page I am working on is similar > > to the iGoogle page where you have movable widgets arranged in 3 > > columns. Widgets can be moved up and down in their column and even > > between columns. I''m primarily using the Scriptaculous Sortables class > > to make columns sortable with each other. Column order is saved and > > restored via the Sequence and setSequence function calls and cookies. > > That part was straight forward. However, I need a method to move the > > widgets to the correct column div before calling setSequence. Right > > now the code is repetitive, but it''s just a first draft. :) Here is > > the full function: > > > Columns are divs with id''s of "col-0", "col-1", and "col-2" > > Widget are divs with id''s like "w_2" and "w_20" and are contained in > > columns > > There is one cookie per column that contains a list of integers > > separated by commas, the integers correspond to the order the widgets > > should appear in the column. > > > function orderWidgetsByColumn() { > > //these are string containing integers separated by commas > > //example: 2,18,3,19,3 > > var widgetListStr0 = getCookie(''col-0''); > > var widgetListStr1 = getCookie(''col-1''); > > var widgetListStr2 = getCookie(''col-2''); > > > //if all cookies are set, move all widgets to the correct column > > if( widgetListStr0.length > 0 && > > widgetListStr1.length > 0 && > > widgetListStr2.length > 0 ) { > > > //convert the comma delimited strings to arrays > > var col0 = widgetListStr0.split('',''); > > var col1 = widgetListStr1.split('',''); > > var col2 = widgetListStr2.split('',''); > > > var x; > > var w_id = ""; > > > //step through the first column > > for( x in col0 ) { > > w_id = ''w_'' + col0[x]; > > > //if the current item is not in col0, move it there > > if( ! ($(w_id).descendantOf(''col-0'')) ) { > > $(''col-0'').insert(document.getElementById(w_id)); > > } > > > } > > > //step through the second column > > for( x in col1 ) { > > w_id = "w_" + col0[x]; > > > //if the current item is not in col0, move it there > > if( ! ($(w_id).descendantOf(''col-1'')) ) { > > $(''col-1'').insert(document.getElementById(w_id)); > > } > > } > > > //step through the third column > > for( x in col2 ) { > > w_id = "w_" + col0[x]; > > > //if the current item is not in col2, move it there > > if( ! ($(w_id).descendantOf(''col-2'')) ) { > > $(''col-2'').insert(document.getElementById(w_id)); > > } > > } > > > } > > > return; > > > } > > > On May 8, 5:20 am, "Martin Ström" <martinstromli...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > What is the contents of your "col0" variable? > > > If it''s an array you should not use the "for (x in ...)" loop but a > > > traditional for (x = 0; x < y; x++) loop or Prototype''s Array#each > > > > If you post how you get the col0''s contents setup I''m sure we can help you. > > > > 2008/5/8 Timebomb <twelbo...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>: > > > > > I am trying to write some code using javascript and the prototype > > > > library that makes sure certain divs are contained in a column div, if > > > > they are not they get moved there. I''m getting the error "$(w_id) has > > > > no properties" when I run it. Is it possible to programmatically build > > > > a string containing a div id then use it like I need to? I''m new to > > > > prototype. Thanks in advance. > > > > > Here is my code snippet: > > > > > var x; > > > > var w_id = ""; > > > > > //step through the first column > > > > for( x in col0 ) { > > > > w_id = ''w_'' + col0[x]; > > > > > //if the current item is not in col0, move it there > > > > if( ! ($(w_id).descendantOf(''col-0'')) ) { > > > > $(''col-0'').insert(document.getElementById(w_id)); > > > > } > > > > > } > > > > -- > > > burnfield.com/martin--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---