Reputation: 103
I'm putting together a tournament bracket system allowing you to drag 'winners' to the next round, and if applicable the loser is automatically transfered to his place in a losers bracket. After each drop I'm sending to php details about the match for both individual tracking purposes as well as refilling the positions in the event it is shut down and reopened.
I ran into a problem where I was sending some unwanted characters that I used .replace() to rid myself and now everything on the winners side works fine, but anything on the losers side doesn't. Hoping someone can help me figure out the cause of this.
15: $(window).load(function(){
16: $(".make-draggable, .draggable, .drag").draggable({
17: helper: "clone",
18: snap: ".draggable",
19: snapMode: "inner"
20: });
21: $(".draggable").droppable({
22: drop: function(event, ui) {
23: var elemText = ui.draggable.text();
24: $(this).html(elemText);
25: var outB = ui.draggable.attr('id').split("-");
26: var pl1;
27: var pl2;
28: if (outB[0] == "go") {
29: var num = outB.length;
30: var loser;
31: var loserval;
32: var losloc;
33: var losid = outB[1];
34: var numchars = outB[1].length;
35: if (num === 2) {
36: var i = 1;
37: loser = (losid.charAt(0) + "-");
38: pl1 = elemText;
39: for (i = 1; i < numchars; i++) {
40: loser = (loser+losid.charAt(i));
41: }
42: loserval = $("#go-" + loser);
43: losloc = ("#"+losid);
44: $(losloc).html(loserval.text());
45: pl2 = loserval.text();
46: } else if (num === 3) {
47: loser = (outB[1] + outB[2]);
48: loserval = $("#go-" + loser);
49: losloc = ("#"+loser);
50: $(losloc).html(loserval.text());
51: pl1 = loserval.text();
52: pl2 = elemText;
53: }
54: } else {
55: var getround = $(this).attr('id');
56: if(getround == 'winner') {
57: pl1 = $('#winnerb').text();
58: pl2 = $('#loserb').text();
59: } else {
60: var inti = ui.draggable.attr('id').substring(1);
61: if (inti%2 == 0) {
62: var apl = inti - 1;
63: pl1 = elemText;
64: pl2 = $('#l'+apl).text();
65: alert(apl);
66: } else {
67: var apl = inti++;
68: alert(apl);
69: pl1 = $('#l'+apl).text();
70: pl2 = elemText;
71: }
72: }
73: }
74: var matrou = ui.draggable.parent().attr("id").split("-");
75: $.urlParam = function(name){
76: var results = new RegExp('[\\?&]' + name + '=([^&#]*)').exec(window.location.href);
77: return results[1] || 0;
78: }
79: pl1 = pl1.replace(/(\r\n|\n|\r)/gm,"");
80: pl2 = pl2.replace(/(\r\n|\n|\r)/gm,"");
81: elemText = elemText.replace(/(\r\n|\n|\r)/gm,"");
82: var params = 'win='+elemText+'&p1='+pl1+'&p2='+pl2+'&match='+matrou[3]+'&round='+matrou[1]+'&wloc='+$(this).parent().attr('id')+'-'+$(this).attr('id')+'&lloc='+$(losloc).parent().attr('id')+'-'+$(loserval).attr('id')+'&tid='+$.urlParam('tid');
83: xmlhttp=new XMLHttpRequest();
84: xmlhttp.onreadystatechange=function() {
85: if (xmlhttp.readyState==4 && xmlhttp.status==200) {
86: }
87: }
88: xmlhttp.open("POST","sub_match.php",true);
89: xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
90: xmlhttp.setRequestHeader("Content-length", params.length);
91: xmlhttp.setRequestHeader("Connection", "close");
92: xmlhttp.send(params);
93: }
94: });
95: });
Upvotes: 2
Views: 4098
Reputation: 87073
I think in line 62
pl1 = $('l'+(inti+1));
should be
pl1 = $('l'+(inti+1)).text();
and in line 66
pl2 = $('l'+(inti+1));
should be
pl2 = $('l'+(inti+1)).text();
Upvotes: 0
Reputation: 8640
I am on my phone, so it's a little hard to debug your code, but I noticed that in line 62 and 66, you are just getting an element and assign it to p1, rather than getting the text of that element. Try adding .text() at the end of that line.
Upvotes: 1