1

Submit is disabled for keypress enter on textarea also I want to go the new line when enter is pressed on textarea. How can I modify below code?

$('textarea').bind('keypress', function(e) {
    if ((e.keyCode || e.which) == 13) {
        e.preventDefault();
        return false;
    }
});
orcun
  • 37
  • 8

3 Answers3

1
 <textarea id="post_body"></textarea>

        <text><span></span></text>




      $('#post_body').keyup(function() {    
                $('text').find('span').text($(this).val());
            });





  text span { white-space: pre; }

This is working for me please check link here Jsfiddle

Just code
  • 13,553
  • 10
  • 51
  • 93
0

Normally its works fine. When you hit Enter button on keyboard the cursor will go next line. It will not take submit action for textarea. Try this

<form action="" method="post" enctype="multipart/form-data" name="form1" id="form1" > 
<textarea name="message" cols="50" rows="10" required></textarea><br/>
<input type="submit" name="submit" value="Submit" onclick="storeQueEmail()"/> 
</form>

Here the js fiddle

Selvamani
  • 7,434
  • 4
  • 32
  • 43
0

Try out this ;)

$('textarea').bind('keypress', function(e) {
    if ((e.keyCode || e.which) == 13) {
        e.preventDefault();

        //Just add this line to your code
        $(this).val($(this).val()+'\n');

        return false;
    }
});
Entropyk
  • 117
  • 4
  • thanks for solution, but on Internet Explorer when I write something then press enter it is not go down line, I have to write new things for go down new line. I think it is because of `$(this).val($(this).val()+'\n');` **\n** do you have any idea? @CoolArts – orcun Mar 26 '14 at 08:21