views:

505

answers:

2

I'm trying to create a tagcloud for an application. When I click a tag from the tagcloud, the backgroud for the tag must be changed. Here a simple html code for a tag:

<a about="http://localhost/d456c6" href="http://localhost/d456c6" class="tagweight0 Resource">abda</a>

To change the background i'm using the following:

$('tagweight0').livequery('click', function(event) {
    $(this).toggleClass("select");
    return false;
});

The url whitout selected tags look like this:

http://localhost/exploretags/

and when i have selected tags, it must be something like (JSON format):

http://localhost/exploretags/?selectedTags={"0" : "uri0", "1" : "uri1" , "2" : "uri2"}

I can use $.post to load the page. My problem is, that i have no idea, how to generate the value of the selectedTags parameter. On a click on a tag must be added an element in selectedTag and on click again on the same tag must be deleted, for example

  1. Tagloud whitout selected tags
  2. Click on tag "abc", the url to load is http://localhost/exploretags/?selectedTags={"0" : "http://localhost/tags/abc"}
  3. Click on tag "def", the url to load is http://localhost/exploretags/?selectedTags={"0" : "http://localhost/tags/abc", "1" : "http://localhost/tags/def"}
  4. Click on tag "abc". the url to load is http://localhost/exploretags/?selectedTags={"0" : "http://localhost/tags/def"}

My idea was to write a help function, which get all uris for tags with changed background. But i dont know, how to build the part between {} for the selectedTags parameter.

Can someone give me an idea, how to make this? Is my approach correct?

Regards, Sirakov

PS. Sorry for the long post and for the bad english

A: 

You can use the jQuery JSON plugin.

Greg
would post more but dinner is burning :o
Greg
A: 

You first need to create the json, which is just a javascript hash

and then encode it for use in the url, like this:

encodeURIComponent('{"0" : "uri0", "1" : "uri1" , "2" : "uri2"}')

Or, better yet, post it using the $.post(url, hash, callback) function

mkoryak
one of my problems is, how to create the part {"0" : "uri0", "1" : "uri1" , "2" : "uri2"}.
cupakob