Solved

jQuery sortable no longer working?

Posted on 2013-06-04
5
320 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 51

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 51

Expert Comment

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

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Introduction A frequently asked question goes something like this:  "I am running a long process in the background and I want to alert my client when the process finishes.  How can I send a message to the browser?"  Unfortunately, the short answer …
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery including how to code hide show and toggles. 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…

758 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now