0

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.

Pasindu
  • 340
  • 1
  • 8
  • 24
Nerks
  • 61
  • 1
  • 8
  • 1
    It 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
  • 1
    Take 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 Answers1

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