M
M
MeinJun2020-04-26 14:40:04
JavaScript
MeinJun, 2020-04-26 14:40:04

How on button click from textarea/input put text in a href?

How to make an input field in native js that, on button click, will replace the content of ahref with the content of textarea/input?

<textarea name="siteaddress" cols="150" rows="5"></textarea>
<button name="open">Открыть</button>
<a href="https://learn.javascript.ru/"></a>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
H
hellcaster, 2020-04-26
@MeinJun

const button = document.querySelector(`.open`); // изменить name на клас
const textarea = document.querySelector(`.siteaddress`);
const link = document.querySelector('a');

button.addEventListener(`click`, (e) => {
  e.preventDefault();

  link.href = textarea.value;
});

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question