0

I can't find a solution for this in anywhere. Can someone help me ?

<input type="text" id="myText" oninput="alert(this.value);"><br><br>
<div onclick="document.getElementById('myText').value='123';NowCauseTheEvent,Plz !">
   change
</div>

Basically I need to know how to programatically raise the event input after I change the value programatically as well. (something to place on the "NowCauseTheEvent,Plz" after the document.getElementById('myText').value='123'

ty !

BTW, this is not about custom event, but native event and I will REALLY appreciate to stop to vote for close this one because THIS IS NOT A CUSTOM EVENT !!!!

10
  • Please explain better what you are trying to achieve Commented May 20, 2016 at 11:55
  • Any reason you are running javascript inline rather than in a function? Also can you try explain what you want the client to do and what you want the webpage to do, I'm finding it hard to understand your question... Commented May 20, 2016 at 11:55
  • 1
    Possible duplicate of How to trigger event in JavaScript? Commented May 20, 2016 at 11:56
  • Nope. it's not a duplicated. That thing is for custom event. And this is not a custom event. It's a native event., Justinas. Commented May 20, 2016 at 11:57
  • @NewToJs, I cannot use a function. Long story ! Starts with : I need to send raw html to a 3rd party library. Commented May 20, 2016 at 11:58

2 Answers 2

2

This will work across browsers and trigger the event you require.

<div onclick="document.getElementById('myText').value='123';document.getElementById('myText').oninput()">
    change
</div>

Use the following in your placeholder:

document.getElementById('myText').oninput()
Sign up to request clarification or add additional context in comments.

2 Comments

No worries, glad it helped.
Great answer Ausxor, just beat me to it :p +1 for that!
1

This works for me on Firefox and Chrome but fails on IE11.

<input type="text" id="myText" oninput="alert(this.value);"><br><br>
<div onclick="document.getElementById('myText').value='123'; document.getElementById('myText').dispatchEvent(new Event('input'));">
       change
</div>

1 Comment

Awesome !! That's exactly what I need ! I just need to find a way to make this work in IE...I will try to find a new one to make it work and Ie and then I send you back to edit and you got my "answered"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.