I want to edit links when the user changes the value of a <input type="text">, but I can’t get it to work. My HTML:
<head>
<link rel="stylesheet" href="styles.css" />
<script type="text/javascript">
function updateGiveLink() {
document.getElementById("givelink").innerHTML = "http://kroltan.eliti.com.br/diamonds/?give="+document.getElementsById("givetext").value;
document.getElementById("givelink").href = "http://kroltan.eliti.com.br/diamonds/?give="+document.getElementsById("givetext").value;
}
</script>
</head>
<input type="text" placeholder="Minecraft username" name="give" id="givetext" onchange="updateGiveLink()" />
<a id="givelink" href="http://kroltan.eliti.com.br/diamonds/?give=Player">http://kroltan.eliti.com.br/diamonds/?give=Player</a>
This is supposed to change the URL and display text of givelink so the ?give= part of the url has the value of the text field givetext. But it is not working as expected. Instead, it does nothing. I also tried using onkeyup and oninput (saw these in another related question), with no success.
It should be
document.getElementById("givetext").valueyou hadgetElementsBywith ansWorking code using
onkeyupdemo