title: Uncaught TypeError: Object #<Object> has no method 'replace' line 75
body: <p>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.</p>
  
  <p>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.</p>
  
  <pre><code>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 &lt; 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('[\\?&amp;]' + name + '=([^&amp;#]*)').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+'&amp;p1='+pl1+'&amp;p2='+pl2+'&amp;match='+matrou[3]+'&amp;round='+matrou[1]+'&amp;wloc='+$(this).parent().attr('id')+'-'+$(this).attr('id')+'&amp;lloc='+$(losloc).parent().attr('id')+'-'+$(loserval).attr('id')+'&amp;tid='+$.urlParam('tid');
  83:             xmlhttp=new XMLHttpRequest();
  84:             xmlhttp.onreadystatechange=function() {
  85:                 if (xmlhttp.readyState==4 &amp;&amp; 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:   });
  </code></pre>