title: jQuery adding pages
body: <p>I have made an really ugly code, but i was going to fix it when i was done with it.. But i didn't come that far >_&lt;</p>
  
  <p>i post my code here and some information under it.</p>
  
  <pre><code>$(document).on('click', '.cogwheel', function() { 
          var link = $(this).data('pageid');
          $(".pages").not(".page" + link).hide();
          $(".links").not("#link-" + link).show();
          $("#link-" + link).toggle();
          $(".page" + link).toggle();
      });
      $(document).on('click', '.deletecross', function() {
          $(".deleteClass" + $(this).data('pageid')).remove();
          var total = parseFloat($(".hiddenCounter").val()) - 1; 
          $(".hiddenCounter").val(total);
          var this_val = $(".pagae" + $(this).data('pageid')).val();
          this_val.replace($(".pagae" + $(this).data('pageid')).val(), "");
          $(".pagae" + total).val(this_val);
      });
      $(document).on('keyup', '.pages', function() { 
          var pageID = $(this).data('pageid');
          var pages = $(".pagae").val();
          $(".pagae" + pageID).val($(this).val());
          $(".pagetest" + pageID).html($(this).val());
          $(".pagae").val(pages + $(this).val());
          $("#link-" + pageID).html($(this).val());
      });
  
      message = new Array();
      jQuery.fn.update_textarea = function(test) { 
          //for (i=0;i&lt;test;++i) { 
          if (message[test]) { $(".MenuLinks").append('&lt;tr&gt;&lt;td width="150"&gt;&lt;a href="#" id="link-' + test + '"&gt;Sida ' + test + '&lt;/a&gt;&lt;/td&gt;&lt;td align="right"&gt;&lt;span class="glyphicon glyphicon-cog"&gt;&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;');$("#articles_textarea").append('&lt;h2&gt;askda&lt;/h2&gt;&lt;textarea id="editor-1"&gt;&lt;/textarea&gt;'); }
          else { 
              message[test] = ''; 
              var TDRow1 = '&lt;tr class="deleteClass' + test + '"&gt;&lt;td width="150"&gt;&lt;a href="#Sida' + test + '" id="link-' + test + '" data-toggle="tab" class="links"&gt;Sida ' + test + '&lt;/a&gt;&lt;input type="text" name="pages[]" value="Sida ' + test + '" class="pages page' + test + '" data-pageid="' + test + '"&gt;&lt;/td&gt;';
              var TDRow2 = '&lt;td align="right" width="20"&gt;&lt;span class="glyphicon glyphicon-cog cogwheel" data-pageid="' + test + '" style="cursor:pointer;" title="Redigera"&gt;&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;';
              var TDRowRemove = '&lt;td align="right" width="10"&gt;&lt;span class="glyphicon glyphicon-remove deletecross" data-pageid="' + test + '"  style="cursor:pointer;color: #ff0000;" title="Radera"&gt;&lt;/span&gt;&lt;/td&gt;';
              var TDFake = '&lt;td&gt;&lt;/td&gt;';
              if (test != 1) { 
                  var TRRow = TDRow1 + TDRowRemove + TDRow2; 
              }
              else { 
                  var TRRow = TDRow1 + TDFake + TDRow2; 
              }
              $(".MenuLinks").append(TRRow); $("#articles_textarea").append('&lt;div id="Sida' + test + '" class="tab-pane"&gt;&lt;input type="hidden" class="pagae' + test + '" name="pagae[]" value="Sida ' + test + '"&gt; &lt;h2 class="pagetest' + test + '"&gt;Sida ' + test + '&lt;/h2&gt;&lt;textarea name="editor[]"  id="editor-' + test + '" class="editor" data-pageid="' + test + '"&gt;&lt;/textarea&gt;&lt;/div&gt;'); 
              $("#editor-" + test).wysibb({lang: "en"});
              }
          //}
      }
  
      /* If no textareas available add a new one */ 
      if (message.length == 0) {  
          $(this).update_textarea(1);
          $("#Sida1").addClass("active");
      }
      });
  </code></pre>
  
  <p>This code you can add a page with, delete a page and write a new name for the page, and im using bootstrap so they all got there own "tab" </p>
  
  <p>I was going to use this script to make an article system, and when you post it should insert pages into an own table like <code>pages</code>. And content to another. </p>
  
  <p>But my problem here is, when im trying to remove a "link/page" it removes the page from the menu and everything. </p>
  
  <p>But i dont have a freaking clue how to change the hidden input that has all the names of the pages in it.. So when i post the hidden input i got all pages i have on the page and those i removed.. </p>
  
  <p>I know this is some slabby code and i know you could make it better then me.. </p>
  
  <p>If you got any ideas or any thing that i can make smaller let me know.. </p>