RESOLVED: JQuery - variable is not passing correctly -


resolved, see note in comments below

i'm learning javascript , jquery having problem in code below. have list of players in master list , when double clicked on master list should add team least amount of players. appendto clause not seem work. misusing variable inside of or pointing incorrectly somehow dom? when hard code value team work. i'm using alert see value currentteam passed correctly point , is. doesn't work when in appendto clause.

  note tried create jsfiddle didn't run correctly. tried copying actual sortable jquery example site. again didn't run. 

in example have list of players drafted various teams. have not got checking in place. add later. right want able drag or double click players move across.

i'm not sure why when double click player won't move list if have currentteam in appendto clause if hard code team3 instance, double clicking add player spot. don't want hard code value.

if need better editing i'd appreciate that, or if can work in jsfiddle cool.

<style>     div#info {width:1000px;}     div#contentarea {width:1000px; border:solid 1px blue;}     div#draftlist {width:334px; float:left;}     div#column1 {width:333px; float:left;}     div#column2 {width:333px; float:left;}     .connectedsortable, .sortable,  {list-style-type: none; border: solid 1px black; margin: 0; padding: 0 0 2.5em; width: 333px; } </style>  <script>      $(function() {         $("#masterlist").sortable({             connectwith: ".sortable"         }).on("dblclick", "li", function(){             var numberofplayers = null;             var currentteam = null;              $('.sortable').each(function () {                 var currentnumberofplayers = $(this).children("li").length;                  if (numberofplayers === null || numberofplayers > currentnumberofplayers) {                     numberofplayers = currentnumberofplayers;                     currentteam = $(this).attr('id');                 }             })              alert("current team " + currentteam);              $(this).appendto(currentteam).ul; // doesn't work             // $(this).appendto(team3).ul work don't want hard coded value         });       $( "#team1, #team2, #team3" ).sortable({          connectwith: ".connectedsortable",          receive: function (event, ui) {              if(($(this).find('li').length) >5) {                 $(ui.sender).sortable('cancel');             }          }      }      ).disableselection();     });   </script>     <body> <div id="contentarea">    <div id="draftlist"> draft list: <ul id="masterlist" class="connectedsortable"> <li>player one</li> <li>player two</li> <li>player three</li> <li>player four</li> <li>player five</li> </ul> </div>  <div id="column1"> team one: <ul id="team1" class="sortable"> </ul>  team two: <ul id="team2" class="sortable"> </ul>  team three: <ul id="team3" class="sortable"> </ul>  </div>  </div> <!-- end main content area --> 


Comments

Popular posts from this blog

database - VFP Grid + SQL server 2008 - grid not showing correctly -

jquery - Set jPicker field to empty value -

.htaccess - htaccess convert request to clean url and add slash at the end of the url -