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);" />

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.