0

I have a simple JS quiz on a page that generates answers to question results and places them into the html. On a couple of the answers, id like it to say 'for more information CLICK HERE'. How do I add a link into the JS string that is getting placed into the html?

Im very new to JS so not really sure how to go about this...

This is the JS that is getting called in:

{ // Question
  "q": "<h4>Is it recommended to use one vial of BOTOX<sup>&reg;</sup> on more than one patient?</h4>",
  "a": [
  {"option": "TRUE",      "correct": false},
  {"option": "FALSE",     "correct": true}
  ],
  "correct": "<p><span>CORRECT!</span> As the diluents in BOTOX<sup>®</sup> do not contain a preservative it is not recommended to use on more than one patient.2 If you would like to refer to this information again, it can be found via the link below.</p>",
  "incorrect": "<p><span>INCORRECT.</span> As the diluents in BOTOX<sup>®</sup> do not contain a preservative it is not recommended to use on more than one patient.<sup>2</sup> If you would like to refer to this information again, it can be found via the link below.</p><p>***here is where I would like the link to be***</p>" 
},
DaveP19
  • 167
  • 3
  • 16

1 Answers1

1

You can include links in JavaScript using the link() method:

var str = "This is the text that will show up";
var textToPrint = str.link("http://samplewebsite.com");

You can now print out textToPrint and it will print it out like this: This is the text that will show up.

Eric Wiener
  • 4,929
  • 4
  • 31
  • 40
  • How/where do I add that to the script? And then how do I call the var in the html string? – DaveP19 Dec 09 '16 at 04:54
  • You could add that in your existing block of code (wherever you want that url to be). I'm not really sure what you're trying to do with the existing Javascript. Could you please post more of your code so I have an idea how you are manipulating the HTML. – Eric Wiener Dec 09 '16 at 05:01
  • Oh I just mean how do I write the code to add the link in... So in the above js code I have this -

    ***here is where I would like the link to be***

    - thats where I need to write the link. So how do I call the link var in that space?
    – DaveP19 Dec 12 '16 at 00:47
  • [This](http://stackoverflow.com/questions/3304014/javascript-variable-inside-string-without-concatenation-like-php) explains how to include the link – Eric Wiener Dec 12 '16 at 00:54