0

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>

Edited by godzab

4
Contributors
4
Replies
5
Views
5 Years
Discussion Span
Last Post by JorgeM
1

<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.

2

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

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

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.