Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

78
Views
Javascript Link to Href maker not working

I'm trying to make a simple link to html maker, but the thing is variables aren't working

var text1 = document.getElementById("text1");
var link1 = document.getElementById("link1");
var input = document.getElementById("thetext");
var flink1 = "<a href='" + link1.value + "'>" + text1.value + "</a>";

function generate() {
  input.value = flink1
}
input,
textarea {
  width: 100%;
  height: 50px
}
<textarea id="thetext" class=""></textarea>
<br/><br/>
<input id="link1" placeholder="link"></input><br/><br/>
<input id="text1" placeholder="link title"></input><br/><br/>
<button id="" onclick="generate()"></button>

Can anyone say what's the issue

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

This is your answer.

function generate() {
var text1 = document.getElementById("text1");
var link1 = document.getElementById("link1");
var input = document.getElementById("thetext");
var flink1 = "<a href='" + link1.value + "'>" + text1.value + "</a>";
input.value = flink1;
}
input,
textarea {
  width: 100%;
  height: 50px
}
<textarea id="thetext" class=""></textarea>
<br/><br/>
<input id="link1" placeholder="link"></input><br/><br/>
<input id="text1" placeholder="link title"></input><br/><br/>
<button id="" onclick="generate()">Generate</button>

about 4 years ago · Juan Pablo Isaza Report

0

Your flink1 will always contain empty strings for href and innerText because your generate doesn't update its value upon user input.

Move the variable definition inside generate call, and it'll work as intended.

var text1 = document.getElementById("text1");
var link1 = document.getElementById("link1");
var input = document.getElementById("thetext");

function generate() {
  var flink1 = "<a href='" + link1.value + "'>" + text1.value + "</a>";
  input.value = flink1
}
input,
textarea {
  width: 100%;
  height: 50px
}
<textarea id="thetext" class=""></textarea>
<br/><br/>
<input id="link1" placeholder="link"></input><br/><br/>
<input id="text1" placeholder="link title"></input><br/><br/>
<button id="" onclick="generate()">Generate</button>

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!