1

If I have some PHP HTML that reads like this:

<html> I am feeling <?php print urldecode($_GET["emotion"]);?> today!</html>

and Get's "emotion" in URL title is "Happy", the HTML renders "I am feeling Happy today!".


Now, migrating away from PHP, how do I do this with javascript?

In Javascript I have a variable $emotion = "Happy"; so what Javascript goes inbetween the script tags below (where there are currently asterisks********)

<html> I am feeling <script>*********************</script> today!</html>
Albert Renshaw
  • 17,282
  • 18
  • 107
  • 195
  • And is the 'emotion' still to be found in the URL, as a GET parameter? Have you managed to make a start on this problem at all? And it might not be a good idea to migrate to a language that you don't know. By all means experiment, and learn, but leave migration for later. Php and JavaScript cover different ground. – David Thomas Nov 19 '14 at 01:55
  • @DavidThomas ???? Is this not "experiment / learn"? Hahah, I simply posted this as I am learning. – Albert Renshaw Nov 19 '14 at 01:57
  • It may well be, yes; but 'migrating' is present-tense (a thing you are doing now), whereas if this is learning, then migration (future-tense) is a thing you will do in the future. Which makes more sense. – David Thomas Nov 19 '14 at 02:01
  • @DavidThomas hahaha that word "Migrating" had to do with my asking of the question, I wasn't saying that I was "now migrating away", I was saying, here is my example in PHP, now, migrating away from THAT example, here is my example in JS – Albert Renshaw Nov 19 '14 at 02:29
  • document.write(emotion); ? – J-16 SDiZ Nov 19 '14 at 07:38

1 Answers1

5

You can do it easily by putting an element where you want the text to change, then accessing that element by it's id.

$emotion = "Happy";
var e = document.getElementById('emotion');
e.innerHTML = $emotion;
I am feeling <span id="emotion"></span> today!
JakeParis
  • 11,056
  • 3
  • 42
  • 65