Showing posts with label textarea. Show all posts
Showing posts with label textarea. Show all posts

Thursday, 20 May 2021

Checking textarea empty value using JQuery.

 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<script>

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

    if (!$.trim($("#txtarea").val())) {

       alert("please input something");  //to check textarea is empty or not

}

});

</script>


Above JQuery code will check that textarea is empty or not it will also check white space.

Complete example is given below-

<!DOCTYPE html>

<html>

<body>

<center>

<textarea cols="50" rows="8" id="txtarea" required></textarea>

<br>

<button id="action">Click to check</button>

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<script>

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

   if (!$.trim($("#txtarea").val())) {

       alert("please input something");  //to check textarea is empty or contains only white-space

}

});

</script>

</center>

</body>

</html>

Adding textarea text to any div using Jquery.

 In JQuery, it is very simple to add textarea text to any div on button click. See below how it is possible:

 $("#div").html( $("#txtarea").val() ); //to add text of text area to div

This will add the textarea text to div element.

The complete example is given below-

<!DOCTYPE html>

<html>

<body>

<center>

<textarea cols="50" rows="8" id="txtarea" required></textarea>

<br>

<button id="action">Add text to div</button>

<div id="div"></div>

<!-- Scripts before </body> -->

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<script>

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

  $("#div").html( $("#txtarea").val() ); //to add text of text area to div

});

</script>

</center>

</body>

</html>

Change image source dynamically on hyperlink

 Changing image source dynamically using JQuery. Here in this example I have created there hyperlink and stored all images in the same folde...