Jump to content

how to increase te height of textfield


seco

Recommended Posts

Does this help?

 

<script type="text/javascript">
function addHeight ( ele_id, change ) {
  var ele = document.getElementById(ele_id);
  var h = Number(ele.style.height.replace(/\D/g,''));
  h += change;
  ele.style.height = h + 'px';
}
</script>
<textarea name="mytext" id="mytext" style="width:400px;height:80px;"></textarea><br>
<input type="button" value="Add Height" onclick="addHeight('mytext',20);" />

ele.style.height will return the string '80px'. To turn that into a number we need to drop the px, which is what the replace does. Then Number() casts it from the string 80 to a number, so that when 'change' is added to it, it does addition instead of concatenation.

 

Make sense?

what that does is replace anything matching \D (which in regex means a non-numeric character) with '' (aka: nothing)

 

Pass something like this through it: 'a1b2c3d4' and it will spit out 1234. There are lots of ways to do it, you could use one of the substring methods for instance, and chop off the last 2 characters. You could do a Regex match for \d+, etc. The provided way was just the first that came to mind.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.