In this post we will see how to set value to textarea in jQuery. To assign value to textarea in jquery we can use .val() method of textarea. In example we will take value from input testbox and
assign it to textarea.

Example to set value to textarea [jQuery]
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.11/jquery-ui.min.js"></script>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.11/i18n/jquery-ui-i18n.min.js"></script>
<link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.1/themes/ui-lightness/jquery-ui.css" type="text/css" media="all" />
<title>Set textarea value in jQuery</title>
<script type="text/javascript">
$(document).ready(function () {
$("#submitbtn").click(function () {
var inputVal = $("#inputText").val();
$("#txtMessage").val(inputVal);
});
});
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<label>Type Text here</label>
<input type="text" id="inputText" /><br/>
<textarea cols="50" rows="5" id="txtMessage"></textarea><br/>
<input type="button" id="submitbtn" value="Submit" />
</div>
</form>
</body>
</html>
0 Comments :
Post a Comment