Friday, September 9, 2011

how to resize the textbox height dynamically or how to change or increase the textbox height dynamically based on text using javascript








Introduction:

In this Post I will explain how to  increase the textbox height dynamically based on text writing into text box.

Description:

I have one textbox the requirement is like if any user enters text in texbox that height of textbox needs to be adjusting with text.I have written one JavaScript function to adjust textbox height here one more thing is that we have  to set the TextMode="MultiLine" property for textbox to adjust textbox height

Lets see the aspx Page


<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Automatic Resize TextBox</title>
<script type="text/javascript">
function SettingHeight(txtdesc) {
txtDescription.style.height = txtDescription.scrollHeight + "px";
}
</script>
</head>
<body>
<form id="form1" runat="server">
<asp:TextBox ID="txtDescription" runat= "server" TextMode="MultiLine" onkeyup="SettingHeight(this);"onkeydown="SettingHeight(this);" />
</form>
</body>
</html>


Demo

3 comments:

Narasappa said...

Thanks For Solution.. Its really Very Useful for Developers.. But I wanted To apply This javascript To TextBox within GridView how can i achieve this any suggestions????

With Regards
Ravi C J
(ravi.jadiyannavar@gmail.com)

Kartik Patel said...

Rubby:I have checked by putting the textbox within Gridview and its working fine.but if you have still any doute then you always welcome to contact me....

Elizabeth J. Neal said...

I have one textbox the requirement is like if any user enters text in texbox that height of textbox needs to be adjusting with text.I have written one JavaScript function to adjust textbox height here one more thing is that we have to set the TextMode="MultiLine" property for textbox to adjust textbox height.. shoe lifts for men

Post a Comment