Juned Ansari Juned Ansari - 1 year ago 96
Javascript Question

onchange event of text box not working if i change text value dynamically

Onchange Event Fired when i change on textbox but when i am trying to change textbox value dynamically it doesnot fired why?

here is my simple demo when i click on button i changed textbox value dynamically but still textbox onchange event doesnot fired.

<!DOCTYPE html>
<title>Page Title</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>

<h1>My First Heading</h1>
<p>My first paragraph.</p>
<input type="text" id="txtno" value="" onchange="javascript:alert('Hi');">
<input type="button" id="btnadd" value="ClickMe">



Answer Source

Changing value of input via JS will not trigger .onChange events. You must trigger it manually


I don't see where you change input field value in your code.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download