Display value of TextBox in Label using jQuery
Introduction: Hello Guys, “Welcome back” Today i am here with another one new great article. In this article, I will explain how to fetch value entered by user in the TextBox in Label using jQuery. When user will click on the, then TextBox value will be fetched and showing in the Label by using jQuery.
Code for HTML Page
Implementation: On the HTML page I will place a Textbox for capturing user input, a button for showing the value entered by the user in Textbox, and span for fetching value of TextBox and displaying it on the screen.
Name:<input type="text" id="txt_Name" />
<input type="button" id="button_display" value="Show Name" />
<hr />
<label id="lable_name"></label>
Displaying and showing value of textbox Label using jQuery
On the HTML page I inherited jQuery file named jquery.min.js
Inside the jQuery document ready event handler, the Button has been assigned with a jQuery click event handler. When the user will click on the then the value entered by the user in Textbox will be fetched retrieved and show in Label.
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.7.1/jquery.min.js"></script>
<script type="text/javascript">
$(function () {
$("#button_display").click(function () {
var name = $("#txt_name").val();
$("#lable_name").html(name);
});
});
</script>
Below I am giving the complete code for this function. You can copy and paste the whole code on your HTML page to enjoy the execution of this program.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.7.1/jquery.min.js"></script>
<script type="text/javascript">
$(function () {
$("#button_display").click(function () {
var name = $("#txt_name").val();
$("#lable_name").html(name);
document.getElementById("txt_name").value = "";
});
});
</script>
</head>
<body>
Name:<input type="text" id="txt_name" /><br /><br />
<input type="button" id="button_display" value="Display Entered Name" />
<br /><br />
<label id="lable_name"></label>
</body>
</html>
Conclusion: In above code, I have been explained that how to fetch value entered by user in the TextBox in Label using jQuery.This code is very helpful for every developer. Bye Bye and take care of you Developers. We will come back shortly with the new article.
Thanks and Regards
Using ASP.Net
Good
ReplyDelete