Jump to content

Add event listener to every <input> tag?


grippat

Recommended Posts

I'm trying to figure out how to add an event listener to every input tag. I had this:document.getElementsByTagName('input').onkeyup = function () {alert('testing');}But it didn't seem to do anything. My objective is to have JavaScript send entered form info via AJAX every time the user presses a key. There are multiple inputs so I need the same even listener on each.

Link to comment
Share on other sites

Make sure you run this code AFTER the window has loaded (for example put it in a function and call it with the window.onload event).inp = document.getElementsByTagName("input")for(i=0;i<inp.length;i++) {inp.onkeyup = function () {alert('testing');}}

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...