×

Please Login or Register to continue.

2
(741 Views)

I am creating a project in the JavaScript jQuery library. I want to display text while writing in an HTML text box using jQuery.There is a form where a text box is available inside the form. I want like, whenever start writing in the text box the same text should be displayed on the page. I can use the text area to write my text.

HTML form - 

<form>
   <input type="text" name="content" id="content">
</form>

As you can see in the above code line, I have created a text box. I have seen many websites where I can display the same text on the page while writing in a text box. 

(2.4K Points)
in jquery

Share

1 Answer
(3.4K Points)
1

If you are using the JavaScript jQuery library then it will be very easy to display value while typing in the text box. You can do it using the jQuery keyup() method. I also use this keyup() method to get values while typing in the textbox or textarea. You will need to create an HTML text box or you can create a textarea. Give an id name like - id="content" . You will need a jQuery CDN link. Use the jQuery ready() method and keyup() method using the textbox id. 

Create an example - 

<!DOCTYPE html>
<html>
<head>
   <title>Getting value from the HTML text box while typing in jQuery</title>
</head>
<script src="https://code.jquery.com/jquery-3.6.1.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
    $("#content").keyup(function(){
        var content=$("#content").val();
         $("#display_content").html(content);
     });
});
</script>
<body>
   <p id="display_content"></p>
   <form>
   <input type="text" name="content" id="content" placeholder="Typing">
</form>
</body>
</html>

You can display content id using the html() method while typing. In this way, you can display text on the page while typing in the textbox or textarea in jQuery.


Comment

Related Questions :-

Your Answer

You can post your answer after login..

Live Chat

Hello! How can we assist you today?