seco Posted March 26, 2008 Share Posted March 26, 2008 Hi how to increase te height of textfield i mean te number of lines using javascript? thanks in advance. Quote Link to comment Share on other sites More sharing options...
rhodesa Posted March 26, 2008 Share Posted March 26, 2008 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);" /> Quote Link to comment Share on other sites More sharing options...
seco Posted March 26, 2008 Author Share Posted March 26, 2008 yea works well but why the line of height.replace i think just get the height directly would be enough? or what? Quote Link to comment Share on other sites More sharing options...
rhodesa Posted March 26, 2008 Share Posted March 26, 2008 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? Quote Link to comment Share on other sites More sharing options...
seco Posted March 27, 2008 Author Share Posted March 27, 2008 ok get the main idea but one last question. how replace(/\D/g,'') can replace px? Quote Link to comment Share on other sites More sharing options...
rhodesa Posted March 27, 2008 Share Posted March 27, 2008 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.