views:

42

answers:

1

I have a javascript that displays a generated text into a div: document.getElementById('phrase').innerHTML = phrase; PHRASE_TEXT_GETS_SHOWN_HERE

Basically I'm trying to set up a link that will take the text and post it to twitter with a link: Clicky for tweety

How can I include the generated text in the link?

+1  A: 

Do you mean like:

function setPhrase(phrase) {
  var url = 'http://twitter.com/home?status=' + encode(phrase);
  $('#phrase').html('<a href="' + url + '">' + phrase + '</a>');
}

...?

Un-jQuerying it should be straightforward enough, if that's how you roll.

This is un-jQueried:

function setPhrase(phrase) {
  var url = 'http://twitter.com/home?status=' + encodeURI(phrase);
  document.getElementById('phrase').innerHTML = '<a href="' + url + '">' + phrase + '</a>';
}

If you didn't see my failbraining encode for encodeURI as an error you should use Firebug. It may also fail if you have more than one element with the id phrase or if you have no elements with the id phrase.

wombleton
That's what I meant. I'll have a go at de jQuerying it but might be back if I get stuck - thanks!
Finne
Sorry... I'm completely lost here. I tried adding jQuery as I couldn't get it to work any other way, but the addition of jQuery didn't work for me.
Finne
Finne