Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Entire form onChange

Tags:

javascript

How can I use onChange or a similar event for all form elements? I don't want to use onChange for each field separately.

like image 772
Mori Avatar asked May 25 '12 20:05

Mori


People also ask

How do I use Onchange in form?

Definition and UsageThe onchange event occurs when the value of an element has been changed. For radiobuttons and checkboxes, the onchange event occurs when the checked state has been changed.

What is function of Onchange form event?

The onchange attribute fires the moment when the value of the element is changed. Tip: This event is similar to the oninput event. The difference is that the oninput event occurs immediately after the value of an element has changed, while onchange occurs when the element loses focus.

Can a div have Onchange?

No; the onchange attribute is only applicable to form field elements ( input , select , textarea , etc). Thanks for your answer.

Can I use Onchange in button?

The problem is that buttons can't have a onChange property. Why? Because buttons don't have a field to change with. All the elements in HTML who can be used with a onChange property have a field.


1 Answers

You can use the change event on the form element:

var form = document.querySelector('form'); form.addEventListener('change', function() {     alert('Hi!'); }); 
like image 98
Mori Avatar answered Oct 11 '22 05:10

Mori