use textContent
for label
document.getElementById("utmatning").textContent = obj.value
Question
I want to display the value of an <input>
to a label or something like that, by using onkeyup so it's real time. But can only do it by using a second input instead of the label but I just want to display the value.
This is my Javascript function:
function copyTo(obj) {
document.getElementById("utmatning").value = obj.value
}
And the HTML:
<label>E-post:</label>
<input id="inmatning" type="text" onkeyup="copyTo(this)" placeholder="Skriv in e-post…">
<span>Vår återkoppling kommer att skickas till:</span>
<br>
<label id="utmatning"></label>
Solution
OTHER TIPS
You can also call the keyup function of jquery and update the label on every keystroke: http://api.jquery.com/keyup/
try this
$( "#inmatning" ).keyup(function() {
$("#utmatning").text($("#inmatning").val());
});
Or
$( "#inmatning" ).keyup(function() {
$("#utmatning").html($("#inmatning").val());
});
both should work
Try this also if you are seeking short method use jquery :
$( "#inmatning" ).keyup(function() {
$("#utmatning").text($(this).val());
});
or use
$( "#inmatning" ).keyup(function() {
$("#utmatning").text($("#inmatning").val());
});
but you are using function then you can also use:
function copyTo(that){
$("#utmatning").text($(that).val());
}