I didn't go through ALL that code, but it seems that if you pulled collections of child nodes (http://www.w3schools.com/jsref/dom_obj_all.asp) rather than getting > var child=listElement.firstChild; and trying to iterate over siblings, you might be able to simplify your code a great deal and make it easier to get it operating.
The logic of starting with firstChild as the beginning of your iteration seems very dodgy. Don On Mon, Apr 26, 2010 at 9:15 AM, cricket <[email protected]> wrote: > You probably won't get much response here if all you have to say is > that something is "not working properly" and then post a lot of > javascript code. Are you sure this is even a CakePHP issue? > > On Apr 26, 2:53 am, rakeshyadav rakeshyadav > <[email protected]> wrote: > > Hi all, > > > > I am using javascript in my cake view page and trying to call > that > > functions they are not working properly please help me. > > > > my code is > > <html> > > <head> > > > > <script type="text/javascript" language="javascript"> > > window.onload = makeCollapsible; > > > > /* CLOSED_IMAGE - the image to be displayed when the sublists are > closed > > * OPEN_IMAGE - the image to be displayed when the sublists are > opened > > */ > > CLOSED_IMAGE='img/plus.jpg'; > > <?php echo $html->image('plus.jpg'); > > ?> > > OPEN_IMAGE='img/minus.jpg'; > > > > /* makeCollapsible - makes a list have collapsible sublists > > * > > * listElement - the element representing the list to make > collapsible > > */ > > function makeCollapsible(){ > > > > listElement = document.getElementById('computers'); > > > > // removed list item bullets and the sapce they occupy > > listElement.style.listStyle='none'; > > listElement.style.marginLeft='0'; > > listElement.style.paddingLeft='0'; > > > > // loop over all child elements of the list > > var child=listElement.firstChild; > > while (child!=null){ > > > > // only process li elements (and not text elements) > > if (child.nodeType==1){ > > > > // build a list of child ol and ul elements and hide them > > var list=new Array(); > > var grandchild=child.firstChild; > > while (grandchild!=null){ > > if (grandchild.tagName=='OL' || grandchild.tagName=='UL'){ > > grandchild.style.display='none'; > > list.push(grandchild); > > } > > grandchild=grandchild.nextSibling; > > } > > > > // add toggle buttons > > var node=document.createElement('img'); > > node.setAttribute('src',CLOSED_IMAGE); > > node.setAttribute('class','collapsibleClosed'); > > node.onclick=createToggleFunction(node,list); > > child.insertBefore(node,child.firstChild); > > > > } > > > > child=child.nextSibling; > > } > > > > } > > > > /* createToggleFunction - returns a function that toggles the sublist > > display > > * > > * toggleElement - the element representing the toggle gadget > > * sublistElement - an array of elements representing the sublists > that > > should > > * be opened or closed when the toggle gadget is > > clicked > > */ > > function createToggleFunction(toggleElement,sublistElements){ > > > > return function(){ > > > > // toggle status of toggle gadget > > if (toggleElement.getAttribute('class')=='collapsibleClosed'){ > > toggleElement.setAttribute('class','collapsibleOpen'); > > toggleElement.setAttribute('src',OPEN_IMAGE); > > }else{ > > toggleElement.setAttribute('class','collapsibleClosed'); > > toggleElement.setAttribute('src',CLOSED_IMAGE); > > } > > > > // toggle display of sublists > > for (var i=0;i<sublistElements.length;i++){ > > sublistElements[i].style.display= > > (sublistElements[i].style.display=='block')?'none':'block'; > > } > > > > } > > > > } > > > > function edit_store(sel_stores, grp_name, grp_id) > > { > > document.getElementById('selected_stores').value = sel_stores; > > document.getElementById('group_name').value = grp_name; > > document.getElementById('sgid').value = grp_id; > > > > document.getElementById('idd').value = '153'; > > document.getElementById('store_grid').submit(); > > } > > </script> > > > > <script type="text/javascript" language="javascript"> > > function create_new_group() > > { > > document.getElementById('idd').value = '153'; > > document.getElementById('store_grid').submit();} > > > > </script> > > > > <strong> > > <?php echo $html->link('Gauteng > > Division', '#', > > > array( > > > > 'class'=>'url2_font', > > > > 'font-fomily'=>'Verdena', > > > > 'onclick'=>'edit_store('3_4_', > > > > 'Gauteng Division', '3')); > > ?> > > > > </strong> > > > > Check out the new CakePHP Questions sitehttp://cakeqs.organd help others > with their CakePHP related questions. > > > > You received this message because you are subscribed to the Google Groups > "CakePHP" group. > > To post to this group, send email to [email protected] > > To unsubscribe from this group, send email to > > [email protected]<cake-php%[email protected]>For > > more options, visit this group athttp:// > groups.google.com/group/cake-php?hl=en > > Check out the new CakePHP Questions site http://cakeqs.org and help others > with their CakePHP related questions. > > You received this message because you are subscribed to the Google Groups > "CakePHP" group. > To post to this group, send email to [email protected] > To unsubscribe from this group, send email to > [email protected]<cake-php%[email protected]>For > more options, visit this group at > http://groups.google.com/group/cake-php?hl=en > Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions. You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
