0

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>
1
  • 1
    u need to use "innerHTML" if u want content from <label id="utmatning"></label> Commented Sep 27, 2013 at 12:34

4 Answers 4

2

use textContent for label

 document.getElementById("utmatning").textContent = obj.value

DEMO

Sign up to request clarification or add additional context in comments.

1 Comment

OP added the jQuery tag as well
0

You can also call the keyup function of jquery and update the label on every keystroke: http://api.jquery.com/keyup/

Comments

0

try this

$( "#inmatning" ).keyup(function() {
    $("#utmatning").text($("#inmatning").val());
});

Or

$( "#inmatning" ).keyup(function() {
    $("#utmatning").html($("#inmatning").val());
});

both should work

Comments

0
    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());
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.