Forum Moderators: open

Message Too Old, No Replies

Expanding textarea on the fly

         

dreamcatcher

8:14 am on May 25, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The vBulletin software has a snazzy little function where by you can expand the textarea box on the fly using javascript. So, if someone is starting to see a scroll bar when they are typing their message, they can click 'Expand' and the textarea increases vertically.

I can do it in PHP which is pretty easy, but the page has to refresh thus losing the data.

I`ve looked through the vBulletin js code and can`t seem to find the javascript function that makes this work. I can see the function names in the code, but can`t find the js.

Anyway, any of you guys know of a little code snippet that creates this effect?

Thank you.

birdbrain

12:24 pm on May 25, 2005 (gmt 0)



Hi there dreamcatcher,

have a peep at this 'de luxe' version. ;)
It has horizontal control also.


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>textarea expander</title>
<meta http-equiv="Content-Type" content="application/xhtml+xml; charset=utf-8" />
<style type="text/css">
/*<![CDATA[*/
body {
background-color:#ddd;
}
#theForm {
font-family:verdana,arial,helvetica,sans-serif;
}
#theForm fieldset {
margin: 30px auto;
padding:10px;
background-color:#ccc;
border:8px inset #ccc;
}
#theForm textarea {
font-size:14px;
}
#theForm div {
text-align:center;
}
#theForm input {
width:95px;
font-size:14px;
margin:5px 0px;
}
/*//]]>*/
</style>
<script type="text/javascript">
//<![CDATA[
var df=document.forms;
function initiateWidth() {
df[0][0].style.width=df[0][1].offsetWidth+"px"
}
function expandTextarea(which) {
if(which==0) {
df[0][1].rows=df[0][1].rows+1;
df[0][0].style.height=df[0][1].offsetHeight+25+"px";
}
else {
df[0][1].cols=df[0][1].cols+1;
df[0][0].style.width=df[0][1].offsetWidth+"px";
}
}
//]]>
</script>
</head>
<body onload="initiateWidth()">
<form id="theForm" action="#">
<fieldset>
<textarea cols="22" rows="2"></textarea>
<div>
<input type="button" value="expand rows" onclick="expandTextarea(0)"/>
<input type="button" value="expand cols" onclick="expandTextarea(1)"/>
</div>
</fieldset>
</form>
</body>
</html>

birdbrain

dreamcatcher

12:38 pm on May 25, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



birdbrain, that is just fabulous, thank you very much.

dc

:)

birdbrain

3:13 pm on May 25, 2005 (gmt 0)



No problem, I'm pleased that you liked it. ;)

birdbrain