views:

41

answers:

2

Hi,

Can anyone please let me how to Enlarge textarea while using OnClick function or how to increase the rows on onClick?

regards balkar

+3  A: 

If you can set pixel or column sizes (instead of using the rows and cols attributes), you can use the :focus CSS pseudo-class:

HTML:

<textarea id="myarea"></textarea>

CSS:

textarea#myarea { width: 100px; height: 20px; }
textarea#myarea:focus { width: 500px; height: 200px; }

depending on the layout, it's sometimes attractive to give the focused textarea position: absolute so it floats above the other elements in its enlarged state.

Pekka
A: 

If you wanna use onClick, add an onClick Handler via JavaScript:

<html>  
    <body onLoad="load();">   
        <textarea id="t1">foo</textarea>
        <script>
        function load(){
            document.getElementById("t1").addEventListener("click",function(){ 
                this.setAttribute("rows","50"); 
            },false);  
        }  
        </script> 
    </body>
 </html>
Hannes