0

I have a form for translating text and would like to have the form submit as the user enters characters. Similar to google translate.



Here is code sample:

<form id="trans" method="post" action="prevedi.php">
<textarea id="prevedi" name="prevedi" style="margin: 2px; height: 137px; width: 380px;"></textarea>
<textarea id="prevod" disabled="disabled" name="prevod" style="margin: 2px; height: 137px; width: 380px; border: 0px;" readonly></textarea>
<input name="translate" type="submit" value="Translate"/>

Any idea, how to do this?

Timeout
  • 7,759
  • 26
  • 38
r00t-err0r
  • 174
  • 1
  • 11
  • Possibly similar issue as [here](http://stackoverflow.com/questions/2823733/textarea-onchange-detection) in StackOverflow – i-bob Jan 21 '14 at 22:59
  • 1
    Are you wanting to return a translation to another textarea or div as well? on change will input the form every time a letter gets typed, you might want to think about that as well and do an on blur or something so it only inputs after a complete change. – pathfinder Jan 21 '14 at 23:03

2 Answers2

0
$(document).ready(function(){$("#prevedi").change(function(){$("form").post();});});
user2930100
  • 346
  • 4
  • 10
0
$('#texterea#prevedi').on('keyup',function(){
   $.ajax({
     url: url,
     dataType: 'json',
     type: "post",
     data: {'word',$(this).val()},

     success: function (result) {
       $('#texterea#prevod').val(result.value);
     },
     error: function (error) {

     }
   });

 });
Shhade Slman
  • 263
  • 2
  • 10