As the title said, how would I get text from a input tag and show it dynamicly. So whenever i press a, it shows up in a p tag. How would I do this in jQuery?

EDIT: Here is what I have but its not working:

<html>

    <head>
        <title>update text realtime</title>
        <script type="text/javascript">
            update(src) {
                var a = src.value;
                document.getElementById("text").innerHTML = a;

            }
        </script>
    </head>

    <body>

        <input type="text" name="in" onKeyUp="update(this);" />

        <br />
        <p id="text"></p>
    </body>

</html>

Recommended Answers

All 4 Replies

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js"></script>

For jQuery commands to work you have to include the library for it in the <head> section of the page.

It would be something like this:

$(function(){ // OnLoad
    $("#MyInputID").keyup(function(){ // Key Up Event
        var val = $(this).val(); // Get value from input
        $("#MyParagraphID").html(val); // Set p html
    });
});

Thanks guys it works now, but also how would I do this in plain javascript?

You were close...

add the word "function" on line 6 from above.

function update(src) {
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.