jQuery

Examples On Using jQuery to Alert Textbox Value

Have you been caught up trying to figure out how to alert textbox value using jQuery? In this article, I am going to share with you  a very simple & easy way to use jquery to alert textbox value by using just single line of code. Follow along for more info.

Examples to Alert Textbox Value using jQuery

Let’s assume that you have a textbox with ID “name”. You can alert textbox value using jQuery in the following way:

<script type="text/javascript">
$(document).ready(function() {

var value = $("#name").val();

alert(value);

});

</script>

When you save the above code & view the page in your browser, you will notice an alert that gives the value of the textbox. If you would rather alert the textbox value when a button with ID “my_button” is clicked, you may use the code below:

$('#my_button').click(function() {

var value = $("#name").val();

alert(value);

});

If you have a class of “my_button_class” applied to a button & you want to alert textbox value when this button is clicked, you can use the following code:

$('.my_button_class').click(function() {

var value = $("#name").val();

alert(value);

});

When you use the above code, just make sure that you use the proper ID & Class in your own code in order for the code to work properly. So that’s one fine way to use jQuery to alert the textbox value. You can apply the same tip to alert textarea value.

Simple, isn’t it?

Do you know of other ways to alert textbox value using jQuery? Please feel free to share by commenting below.

Share your thoughts, comment below now!

*

*