Solved

jQuery sortable no longer working?

Posted on 2013-06-04
5
327 Views
Last Modified: 2013-06-05
I have been using jQuery sortable, but for some strange reason it's no longer working and I am pretty sure I have not changed my code.
 
The function below is getting the number of menutab but not the position, which show up as undefined?
 
Any ideas on what is going wrong?

 $(function() {
		$("#sortable1").sortable({'update': function(event, ui){
		 
		 var position='';
		  
		  alert("sortable1 this.children.length"+this.children.length);
		  
		  
		  for (i=0; i < this.children.length; i++) {
			if (position.length) {
			  position += ',';
			}
			position += this.children[i].icon_id ;
		  }
			  
			   alert("sortable1"+position);
			   $.ajax({ url: "arrange_icons.php?group_name=C&position="+position });
		}
	  }); 

 });




<div id="slickbox1">
<ul id="sortable1" class="connectedSortable">
        <li class="my_icon" icon_id='99'>
        <div class="menutab">
<div class="menutabicon"><a href="view_tutorials.php"><img src="/admin/icons/images/tutorials.jpg" alt="Help Tutorials" width="50" height="50" border="0"/></a></div>
<div class="menutablink"><a href="view_tutorials.php">Help/Tutorials</a></div>
</div>
    </li>
	    <li class="my_icon" icon_id='57'>
        <div class="menutab">
<div class="menutabicon">
<a href="/admin/add_webpage.php" target="_self"><img src="/admin/icons/images/add_webpage.jpg" alt="Add New Page" width="50" height="50" border="0"/></a></div>
<div class="menutablink">
  <a href="/admin/add_webpage.php" target="_self">Add New WebPage</a></div>
</div>
    </li>
	    <li class="my_icon" icon_id='58'>
        <div class="menutab">
<div class="menutabicon">
<a href="/admin/menu_layout.php" target="_self"><img src="/admin/icons/images/edit_page.jpg" alt="Update Menu" width="50" height="50" border="0"/></a></div>
<div class="menutablink">
  <a href="/admin/menu_layout.php" target="_self">Edit WebPage</a></div>
</div>
    </li>
	    <li class="my_icon" icon_id='76'>
        <div class="menutab">
<div class="menutabicon"><a href="../index.php" target="_blank"><img src="/admin/icons/images/homepage.jpg" alt="Website Home Page" width="50" height="50" border="0" /></a></div>
<div class="menutablink"><a href="../index.php" target="_blank">Website Home Page</a></div>
</div>
    </li>
	</ul>

</div>

Open in new window

0
Comment
Question by:sabecs
  • 2
  • 2
5 Comments
 
LVL 82

Expert Comment

by:hielo
ID: 39220976
>> this.children
try:
 $(this).children()
0
 

Author Comment

by:sabecs
ID: 39220995
Thanks hielo, but same problem.
0
 
LVL 55

Accepted Solution

by:
Julian Hansen earned 500 total points
ID: 39221317
There were several problems - see below for working script
<script type="text/javascript">
 $(function() {
  $("#sortable1").sortable({'update': function(event, ui){
      var position='';

      alert("sortable1 this.children.length"+$(this).children.length);
      var kids = $(this).children();

      for (i=0; i < kids.length; i++) {
        if (position.length) {
          position += ',';
        }
        position += $(kids[i]).attr('icon_id');
      }

      alert("sortable1"+position);
      $.ajax({ url: "arrange_icons.php?group_name=C&position="+position });
    }
  }); 
});
</script>

Open in new window

0
 

Author Closing Comment

by:sabecs
ID: 39223723
Thanks Julian, that is perfect..
0
 
LVL 55

Expert Comment

by:Julian Hansen
ID: 39223940
You are welcome - thank for the points.
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

What is a Lightbox? A Lightbox is the effect you see when you click, for example, an image and the screen fades out and up pops the same image but in its full size dimensions. There are lots of Lightbox effects for jQuery. Problem is they are a…
PROBLEM: The other day I was working on adding an ajax request to a webpage that already had a dialog box on the page.  The dialog box was using relative positioning to be positioned next to a form field I had on the page.  Everything was working…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question