How do I let users choose (in a number field) how many lines of a textarea to show? I would have some demo code but unfortunately I just didn't know where to start.
Asked
Active
Viewed 99 times
0
-
1It would be better to do this with JS than PHP (otherwise dual form processing would be required, and the PHP is doing something JS can). – user3783243 May 31 '18 at 12:38
-
1Take a look here: https://stackoverflow.com/questions/7745741/auto-expanding-textarea . Though it's not exactly what you want, the gist should be clear. Instead of an event on the textarea, you set the event on the number input et voila. – Loek May 31 '18 at 12:46
1 Answers
0
Here you go JSFiddle Example
HTML
Text area lines: <input id="lineNoInput" type="number" name="lines" value="2">
<br/><br/>
<textarea id="textArea" name="text" form="usrform" rows="2" cols="36">Enter text here...</textarea>
JavaScript (jQuery)
$('#lineNoInput').on("change paste keyup", function() {
$('#textArea').attr('rows', $('#lineNoInput').val());
});
Hope this is what you're looking for.

George K
- 481
- 2
- 13
-
This is great, thanks, but I want to force users not to see anymore than X lines, because I can scroll down if there is more than X lines. – Nerks May 31 '18 at 13:01
-
@Nerks You mean you don't want them to be able to adjust the size of the textbox? – George K May 31 '18 at 13:04
-
-
@Nerks then just do this https://stackoverflow.com/questions/5271782/how-to-disable-the-resize-grabber-of-an-html-textarea and don't forget to close your answer if you've figured it out – George K Jun 03 '18 at 08:03
-