Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #38449

Re: Multiple inputs with same event

Newsgroups comp.lang.javascript
Subject Re: Multiple inputs with same event
From "Evertjan." <exxjxw.hannivoort@inter.nl.net>
References <9KednS9A0scWq0HDnZ2dnUU7-TnNnZ2d@westnet.com.au> <hk3p01Fo3trU1@mid.individual.net>
Date 2020-06-07 13:09 +0200
Message-ID <XnsABD585D5CA71Deejj99@194.109.6.166> (permalink)

Show all headers | View raw


Arno Welzel <usenet@arnowelzel.de> wrote on 07 Jun 2020 in 
comp.lang.javascript:

> Andrew Poulos:
> 
> [...]
>> Is there a way for multiple inputs to call the same function when the 
>> same event occurs to any of them without directly attaching the event to 
>> each input? Or should a just write a function that dynamically attaches 
>> the required events?
> 
> Without attaching the event to a handler there is handler at all.
> 
> If you need different handlers for different input element types,
> iterate through the DOM and attach the handler depending on the type.
> one for blur events and another for checking or unchecking things.

Well no, the handler could test the sort/type of input on execution.

<input class='sort123' onblur='doIt(this)' ..
<input class='sort456' onblur='doIt(this)' ..

const doIt = (t) => {
    	if (t.className == 'sort123') alert(t.value.toUpperCase());
    	if (t.className == 'sort456') alert('456');
    	// ..... or do nothing
};

> But however you do it - there is no other way than attaching an event
> handler to each input element. There is no gobal "some input has some
> change" event.

Quite.

-- 
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)

Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Multiple inputs with same event Andrew Poulos <ap_prog@hotmail.com> - 2020-06-07 10:36 +1000
  Re: Multiple inputs with same event Arno Welzel <usenet@arnowelzel.de> - 2020-06-07 11:06 +0200
    Re: Multiple inputs with same event "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2020-06-07 13:09 +0200
      Re: Multiple inputs with same event Luuk <luuk@invalid.lan> - 2020-06-07 15:40 +0200
        Re: Multiple inputs with same event "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2020-06-08 00:37 +0200
          Re: Multiple inputs with same event Julio Di Egidio <julio@diegidio.name> - 2020-06-08 07:44 -0700
  Re: Multiple inputs with same event James Kirk <noneya.invalid@gmail.com> - 2020-06-07 10:30 -0400
  Re: Multiple inputs with same event JJ <jj4public@vfemail.net> - 2020-06-07 23:49 +0700
  Re: Multiple inputs with same event "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2020-06-07 12:56 -0700
    Re: Multiple inputs with same event Andrew Poulos <ap_prog@hotmail.com> - 2020-06-08 11:39 +1000
      Re: Multiple inputs with same event Gregor Kofler <usenet@gregorkofler.com> - 2020-06-08 11:33 +0200
    Re: Multiple inputs with same event Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2020-06-09 02:49 +0200
      Re: Multiple inputs with same event Andrew Poulos <ap_prog@hotmail.com> - 2020-06-10 17:19 +1000
        Re: Multiple inputs with same event Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2020-06-10 17:12 +0200
          Re: Multiple inputs with same event Andrew Poulos <ap_prog@hotmail.com> - 2020-06-11 15:43 +1000

csiph-web