Forum Moderators: open

Message Too Old, No Replies

Javascript button expands textarea height

         

Gero_Master

2:50 pm on May 3, 2006 (gmt 0)

10+ Year Member



Hello!

Can anyone code for this script where is
2x buttons (+ & -)
1x textarea

+ button click increases the height of the textarea a bit (more rows)

- does the opposite

I had some hard time looking through google as nothing seemed matching my query :/

birdbrain

4:16 pm on May 3, 2006 (gmt 0)



Hi there Gero_Master,

try this, it may suit your requirements...



<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

<style type="text/css">
<!--
input {
width:40px;
margin-bottom:10px;
}
textarea {
overflow:auto;
}
-->
</style>

<script type="text/javascript">
<!--
var rws=5;
onload=function() {
var inp=document.getElementsByTagName('input');
for(c=0;c<inp.length;c++) {
if(inp[c].value=='+') {
inp[c].onclick=function() {
increase();
}
}
if(inp[c].value=='-') {
inp[c].onclick=function() {
decrease();
}
}
}
}

function increase() {
rws++;
document.getElementById('txtara').rows=rws;
}

function decrease() {
if(rws>5) {
rws--;
document.getElementById('txtara').rows=rws;
}
}
//-->
</script>

</head>
<body>

<div>
<input type="button" value="+">
<input type="button" value="-">
</div>

<div>
<textarea id="txtara" rows="5" cols="20"></textarea>
</div>

</body>
</html>


birdbrain