Oliver Levay Oliver Levay - 1 year ago 73
HTML Question

Add a user variable to a link in HTML

I'm trying to make a script where a user types in a string that will be added to a link. I don't know much about Javascript or HTML so this example will be really weird.

var base = "https://www.youtube.com/watch?v=";

var userInput = ReadForm();

button {

<link>base + userInput</link>;


So lets say the user enters "dQw4w9WgXcQ" the link would be:

var base = "https://www.youtube.com/watch?v="

var user input = "dQw4w9WgXcQ"

Link= https://www.youtube.com/watch?v=dQw4w9WgXcQ

Any help is appreciated :)

Answer Source

You can do it like this

$("#add").click(function() {
  var link;
  var utubeLink = "https://www.youtube.com/watch?v=";
  link = utubeLink + $("#get").val();

$("#go").click(function() {
  var utubeLink = "https://www.youtube.com/watch?v=";
  link = utubeLink + $("#get").val();
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="text" id="get">
<button id="add">
<button id="go">
<text id="display"></text>

Here is the jsFiddle

Hope it helps :)

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download