Wednesday, June 9, 2021

"contenteditable" div as replacement for textarea that stretches to fit content

 A while back I made this simple invoice maker and I decided I wanted to make the line items multiline. But it seems like it's weirdly hard to get a textarea to stretch to content! One suggestion from that page is to make a div with the "contenteditable" property... then you get the usual div niceness of stretching to fit content. 

I had to come up with a javascript hack to copy the div contents into hidden form variables onsubmit:

    function loadDescAsHidden(){

        window.desc1.value = window.desc1div.innerHTML;

        window.desc2.value = window.desc2div.innerHTML;

        window.desc3.value = window.desc3div.innerHTML;

    }

So not the prettiest, but good enough for my purposes.

No comments:

Post a Comment