Results 1 to 3 of 3
  1. #1
    Senior foxboyprower's Avatar
    Weasyl
    foxboyprower
    Join Date
    Oct 2012
    Location
    Boring center of the USA
    Posts
    104

    Adding Tags via Javascript

    I'm making a firefox addon that'll help users post journals on multiple websites at once. I won't bore you with the details.
    But I've run into an issue on weasyl about adding tags.

    This is the code I was using to put tags into the tag box:
    ______________________

    var cargo = {
    tags: ["These","tags","were","added","with","javascri pt"],
    };

    var z = document.querySelector("#submit-journal-content #submit-form .tagging .listbuilder");
    var tagPadding = ['<li class="listbuilder-entry" unselectable="on"><span class="listbuilder-entry-text">','</span><a class="listbuilder-entry-remove" href="#" role="button" title="Remove sampletag from the list."></a>'];
    var package = "";
    for(var i = 0; i < cargo.tags.length; i = i + 1)
    {
    package = tagPadding[0]+cargo.tags[i]+tagPadding[1];
    console.log(package);
    z.innerHTML = z.innerHTML + package;
    }

    ______________________

    At first glance, this seems to work, but when the journal is submitted, there are no tags on the journal.
    Any idea on what's going wrong?

  2. #2
    Are you also adding the tags to the `tags-textarea` <textarea>? If not, they need to be space-delimited (i.e. `journal problem tagging`). That's where the site gets the actual list of tags and the site's JS just fancifies that with the <li>s.

  3. #3
    Senior foxboyprower's Avatar
    Weasyl
    foxboyprower
    Join Date
    Oct 2012
    Location
    Boring center of the USA
    Posts
    104
    Alright, thanks. I forgot stuff can be displayed without the site storing it. That tends to happen on the fancier sites. Here's my fixed code for all those people of the future having this issue.
    ______________________

    var cargo = {
    tags: ["These","tags","were","added","with","javascri pt"],
    };

    //get tag area
    var WStagBox = document.querySelector("#submit-journal-content #submit-form .tagging .listbuilder");
    var WStags = document.querySelector("#tags-textarea");

    //set tag value
    var tagPadding = ['<li class="listbuilder-entry" unselectable="on"><span class="listbuilder-entry-text">','</span><a class="listbuilder-entry-remove" href="#" role="button" title="Remove sampletag from the list."></a>'];
    var Tags="";
    for(var i = 0; i < cargo.tags.length; i = i + 1)
    {
    Tags = tagPadding[0]+cargo.tags[i]+tagPadding[1];
    WStags.value = WStags.value+cargo.tags[i] + ' ';
    WStagBox.innerHTML = WStagBox.innerHTML + Tags;
    }
    WStags.value.substring(0, WStags.value.length - 1);

    console.log(WStags.value);

 

 

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •