Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

80
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda