0

Possible Duplicate:
How to change the number of rows in the textarea using jQuery

I'm trying to build a comment box that simulates Facebook, where Shift+Enter increases the rows in the textarea while Enter submits the form. I already can capture both events correctly, I'm just wondering if Javascript alone can edit a page's element attributes since it has already been loaded, or if there's another way to do it.

EDIT:

My code block looks like this:

$(this).keypress(function(e) {
    if (e.which == 13 && e.shiftKey) {
        this.rows++;
        e.preventDefault();
    };
});

But this still doesn't seem to work. Again, I've tried placing alerts into this code block so I'm certain the Shift+Enter event is captured, but the textarea's rows just doesn't increase. Any ideas why? :/

Community
  • 1
  • 1
Wakka02
  • 1,491
  • 4
  • 28
  • 44
  • I've tried that, but the textarea box doesn't seem to change when I hit Shift+Enter. I've tried placing alerts in the if-else block to make sure I'm capturing the event, and it does seem to be capturing accurately... – Wakka02 Jun 17 '12 at 14:47
  • Can you show us the code that capture Shift+Enter but won't resize the textarea as in @MarcB link? – FelipeAls Jun 17 '12 at 14:51

1 Answers1

3
$("textarea").keydown(function(e) {
  if(e.shiftKey&&e.keyCode==13) {
    this.rows++;
  }
})
j0k
  • 22,600
  • 28
  • 79
  • 90