Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

On Text correction, trigger event. Possible?

Tags:

javascript

Suppose I have two textarea html elements and what I type in one shows in the other.

Is there a javascript event that will fire when the correct word is selected on the screenshot below?

image1

like image 595
suchislife Avatar asked Oct 26 '25 06:10

suchislife


1 Answers

There's no way to get this from the event. You can write your own 'logic' to detect any words changes by checking the change event.

Small example using the split() and filter() functions to check the changed word:

function inputChange(event, oldvalue) {

    // Old words
    const old = oldvalue.split(' ');
    
    // Current words
    const curr = event.target.value.split(' ');
    
    // Changed words
    const diff = old.filter(x => !curr.includes(x));
    
    // For each changed word
    for (let changeId in diff) {
    
      // Diff
      console.log('Word changed: ', diff[changeId]);
      
      // Optionally, you can get the same index, so you'll know the new value
      const ind = old.indexOf(diff[changeId]);
      console.log('New value: ', curr[ind]);
    } 
}
input { width: 300px; }
<input type='textarea' value='Test txt. Correct this: hoube -> house' onfocus="this.oldvalue = this.value;" onchange="inputChange(event, oldvalue)" />

  • How can i catch the firefox spellcheck correction event?
like image 86
0stone0 Avatar answered Oct 27 '25 20:10

0stone0