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. Link to comment https://forums.phpfreaks.com/topic/97987-how-to-increase-te-height-of-textfield/ 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);" /> Link to comment https://forums.phpfreaks.com/topic/97987-how-to-increase-te-height-of-textfield/#findComment-501360 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? Link to comment https://forums.phpfreaks.com/topic/97987-how-to-increase-te-height-of-textfield/#findComment-501453 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? Link to comment https://forums.phpfreaks.com/topic/97987-how-to-increase-te-height-of-textfield/#findComment-501459 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? Link to comment https://forums.phpfreaks.com/topic/97987-how-to-increase-te-height-of-textfield/#findComment-502502 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. Link to comment https://forums.phpfreaks.com/topic/97987-how-to-increase-te-height-of-textfield/#findComment-502512 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.