Path: csiph.com!newsfeed.xs4all.nl!newsfeed7.news.xs4all.nl!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Arno Welzel Newsgroups: comp.lang.javascript Subject: Re: Is the input type ID passed as a parameter onChange? If not how can i achieve it. Date: Fri, 9 Aug 2019 17:16:31 +0200 Lines: 70 Message-ID: References: <7289e763-fc8c-4686-8f68-12094ee06440@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-Trace: individual.net 759oLX9C3dJgg2FucYVkewWTHKJZqyqMU/Tj6WpfZ2uePuvF9o Cancel-Lock: sha1:9l7Gd53SrGWu2l9EUViUdDHtz5o= In-Reply-To: Content-Language: en-US Xref: csiph.com comp.lang.javascript:37073 On 09.08.19 15:35, Evertjan. wrote: > Arno Welzel wrote on 09 Aug 2019 in > comp.lang.javascript: > >>> So what is so wrong with: >>> >>> onChange="korgvol(this)" >>> >>> or >>> >>> onChange="korgvol(this.value)" >> >> The first one is correct. You pass a reference to the element itself, so >> you can query the value and the id from the element. > > Strange idea of 'correctness'. No, the only possible answer in this case. > It depends on the korgvol(). You proposed two possible solutions and only one is correct for the specific requirement. The OP said, quote: Well i guess it is not, korgvol() will not know it was called from korgvol1? (end of quote) So it seems the onchange handler should not only get the value but also the information which element was changed. And for *THIS* requirement, using onchange="korgvol(this)" is a correct way to achieve this and not onchange="korgvol(this.value)" since the latter one will only pass a value and not the information which element got changed. > If you *also* want the have a button doing > > > > the secoond one might be the preferred choice. This is a different case: 1) onclick() and not onchange() 2) *set* a value and not *read* a value from control > Even > > onChange="korgvol2(this.value, this.id)" > > and > > > > might be someone's preference in a specific case. Sure. But the original question did not include these. -- Arno Welzel https://arnowelzel.de