Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #37061 > unrolled thread
| Started by | Jonas Thörnvall <jonas.thornvall@gmail.com> |
|---|---|
| First post | 2019-08-08 16:50 -0700 |
| Last post | 2019-08-09 17:16 +0200 |
| Articles | 20 on this page of 55 — 10 participants |
Back to article view | Back to comp.lang.javascript
Is the input type ID passed as a parameter onChange? If not how can i achieve it. Jonas Thörnvall <jonas.thornvall@gmail.com> - 2019-08-08 16:50 -0700
Re: Is the input type ID passed as a parameter onChange? If not how can i achieve it. Jonas Thörnvall <jonas.thornvall@gmail.com> - 2019-08-08 16:55 -0700
Re: Is the input type ID passed as a parameter onChange? If not how can i achieve it. "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2019-08-09 00:16 -0700
Re: Is the input type ID passed as a parameter onChange? If not how can i achieve it. Julio Di Egidio <julio@diegidio.name> - 2019-08-09 00:46 -0700
Re: Is the input type ID passed as a parameter onChange? If not how can i achieve it. Jonas Thörnvall <jonas.thornvall@gmail.com> - 2019-08-10 02:03 -0700
Re: Is the input type ID passed as a parameter onChange? If not how can i achieve it. "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2019-08-10 11:12 +0200
Re: Is the input type ID passed as a parameter onChange? If not how can i achieve it. Jonas Thörnvall <jonas.thornvall@gmail.com> - 2019-08-10 02:08 -0700
Re: Is the input type ID passed as a parameter onChange? If not how can i achieve it. Julio Di Egidio <julio@diegidio.name> - 2019-08-10 03:14 -0700
Re: Is the input type ID passed as a parameter onChange? If not how can i achieve it. Jonas Thörnvall <jonas.thornvall@gmail.com> - 2019-08-10 16:32 -0700
Re: Is the input type ID passed as a parameter onChange? If not how can i achieve it. Jonas Thörnvall <jonas.thornvall@gmail.com> - 2019-08-10 16:36 -0700
Re: Is the input type ID passed as a parameter onChange? If not how can i achieve it. dr.j.r.stockton@gmail.com - 2019-08-11 01:39 -0700
Re: Is the input type ID passed as a parameter onChange? If not how can i achieve it. Jonas Thörnvall <jonas.thornvall@gmail.com> - 2019-08-11 02:38 -0700
NEVER use "this" as a variable Re: Is the input type ID passed as a parameter onChange? If not how can i achieve it. "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2019-08-11 11:58 +0200
Re: NEVER use "this" as a variable Re: Is the input type ID passed as a parameter onChange? If not how can i achieve it. "R.Wieser" <address@not.available> - 2019-08-11 12:13 +0200
Re: NEVER use "this" as a variable Re: Is the input type ID passed as a parameter onChange? If not how can i achieve it. "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2019-08-11 12:31 +0200
Re: NEVER use "this" as a variable Re: Is the input type ID passed as a parameter onChange? If not how can i achieve it. "R.Wieser" <address@not.available> - 2019-08-11 20:15 +0200
Re: NEVER use "this" as a variable Re: Is the input type ID passed as a parameter onChange? If not how can i achieve it. Arno Welzel <usenet@arnowelzel.de> - 2019-08-11 17:50 +0200
Re: NEVER use "this" as a variable Re: Is the input type ID passed as a parameter onChange? If not how can i achieve it. "R.Wieser" <address@not.available> - 2019-08-11 20:20 +0200
Re: NEVER use "this" as a variable Re: Is the input type ID passed as a parameter onChange? If not how can i achieve it. dr.j.r.stockton@gmail.com - 2019-08-11 13:54 -0700
Re: NEVER use "this" as a variable Re: Is the input type ID passed as a parameter onChange? If not how can i achieve it. "R.Wieser" <address@not.available> - 2019-08-12 08:48 +0200
Re: NEVER use "this" as a variable Re: Is the input type ID passed as a parameter onChange? If not how can i achieve it. dr.j.r.stockton@gmail.com - 2019-08-13 14:43 -0700
Re: NEVER use "this" as a variable Re: Is the input type ID passed as a parameter onChange? If not how can i achieve it. "R.Wieser" <address@not.available> - 2019-08-14 08:43 +0200
Re: NEVER use "this" as a variable Re: Is the input type ID passed as a parameter onChange? If not how can i achieve it. "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2019-08-12 12:13 +0200
Re: NEVER use "this" as a variable Re: Is the input type ID passed as a parameter onChange? If not how can i achieve it. Arno Welzel <usenet@arnowelzel.de> - 2019-08-12 11:24 +0200
Re: NEVER use "this" as a variable Re: Is the input type ID passed as a parameter onChange? If not how can i achieve it. "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2019-08-12 12:14 +0200
Re: NEVER use "this" as a variable Re: Is the input type ID passed as a parameter onChange? If not how can i achieve it. "R.Wieser" <address@not.available> - 2019-08-12 12:42 +0200
Re: NEVER use "this" as a variable Re: Is the input type ID passed as a parameter onChange? If not how can i achieve it. "R.Wieser" <address@not.available> - 2019-08-12 22:48 +0200
Re: NEVER use "this" as a variable Re: Is the input type ID passed as a parameter onChange? If not how can i achieve it. Arno Welzel <usenet@arnowelzel.de> - 2019-08-13 15:06 +0200
Re: NEVER use "this" as a variable Re: Is the input type ID passed as a parameter onChange? If not how can i achieve it. Arno Welzel <usenet@arnowelzel.de> - 2019-08-13 15:07 +0200
Re: NEVER use "this" as a variable Re: Is the input type ID passed as a parameter onChange? If not how can i achieve it. "R.Wieser" <address@not.available> - 2019-08-13 20:22 +0200
Re: NEVER use "this" as a variable Re: Is the input type ID passed as a parameter onChange? If not how can i achieve it. Arno Welzel <usenet@arnowelzel.de> - 2019-08-14 08:47 +0200
Re: NEVER use "this" as a variable Re: Is the input type ID passed as a parameter onChange? If not how can i achieve it. "R.Wieser" <address@not.available> - 2019-08-14 10:23 +0200
Re: NEVER use "this" as a variable Re: Is the input type ID passed as a parameter onChange? If not how can i achieve it. Ben Bacarisse <ben.usenet@bsb.me.uk> - 2019-08-14 13:45 +0100
Re: NEVER use "this" as a variable Re: Is the input type ID passed as a parameter onChange? If not how can i achieve it. "R.Wieser" <address@not.available> - 2019-08-14 15:10 +0200
Re: NEVER use "this" as a variable Re: Is the input type ID passed as a parameter onChange? If not how can i achieve it. Ben Bacarisse <ben.usenet@bsb.me.uk> - 2019-08-15 00:42 +0100
Re: NEVER use "this" as a variable Re: Is the input type ID passed as a parameter onChange? If not how can i achieve it. Julio Di Egidio <julio@diegidio.name> - 2019-08-14 20:51 -0700
Re: NEVER use "this" as a variable Re: Is the input type ID passed as a parameter onChange? If not how can i achieve it. Ben Bacarisse <ben.usenet@bsb.me.uk> - 2019-08-15 14:12 +0100
Re: NEVER use "this" as a variable Re: Is the input type ID passed as a parameter onChange? If not how can i achieve it. "R.Wieser" <address@not.available> - 2019-08-15 09:09 +0200
Re: NEVER use "this" as a variable Re: Is the input type ID passed as a parameter onChange? If not how can i achieve it. Ben Bacarisse <ben.usenet@bsb.me.uk> - 2019-08-15 14:11 +0100
Re: NEVER use "this" as a variable Re: Is the input type ID passed as a parameter onChange? If not how can i achieve it. "R.Wieser" <address@not.available> - 2019-08-15 17:34 +0200
Re: NEVER use "this" as a variable Re: Is the input type ID passed as a parameter onChange? If not how can i achieve it. Julio Di Egidio <julio@diegidio.name> - 2019-08-19 10:43 -0700
Re: NEVER use "this" as a variable Re: Is the input type ID passed as a parameter onChange? If not how can i achieve it. Arno Welzel <usenet@arnowelzel.de> - 2019-08-14 17:25 +0200
Re: NEVER use "this" as a variable Re: Is the input type ID passed as a parameter onChange? If not how can i achieve it. Jonas Thörnvall <jonas.thornvall@gmail.com> - 2019-08-14 13:10 -0700
Re: Is the input type ID passed as a parameter onChange? If not how can i achieve it. Julio Di Egidio <julio@diegidio.name> - 2019-08-12 09:30 -0700
Re: Is the input type ID passed as a parameter onChange? If not how can i achieve it. Jonas Thörnvall <jonas.thornvall@gmail.com> - 2019-08-12 11:55 -0700
Re: Is the input type ID passed as a parameter onChange? If not how can i achieve it. Jonas Thörnvall <jonas.thornvall@gmail.com> - 2019-08-12 11:58 -0700
Re: Is the input type ID passed as a parameter onChange? If not how can i achieve it. Jonas Thörnvall <jonas.thornvall@gmail.com> - 2019-08-10 18:48 -0700
Re: Is the input type ID passed as a parameter onChange? If not how can i achieve it. Ben Bacarisse <ben.usenet@bsb.me.uk> - 2019-08-11 16:25 +0100
Extracting numbers from strings, using templates (was: Is the input type ID passed as a parameter onChange? If not how can i achieve it.) Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2019-08-12 22:10 +0200
Re: Extracting numbers from strings, using templates (was: Is the input type ID passed as a parameter onChange? If not how can i achieve it.) Jon Ribbens <jon+usenet@unequivocal.eu> - 2019-08-13 00:23 +0000
Re: Is the input type ID passed as a parameter onChange? If not how can i achieve it. Arno Welzel <usenet@arnowelzel.de> - 2019-08-09 11:59 +0200
Re: Is the input type ID passed as a parameter onChange? If not how can i achieve it. "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2019-08-09 13:54 +0200
Re: Is the input type ID passed as a parameter onChange? If not how can i achieve it. Arno Welzel <usenet@arnowelzel.de> - 2019-08-09 14:53 +0200
Re: Is the input type ID passed as a parameter onChange? If not how can i achieve it. "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2019-08-09 15:35 +0200
Re: Is the input type ID passed as a parameter onChange? If not how can i achieve it. Arno Welzel <usenet@arnowelzel.de> - 2019-08-09 17:16 +0200
Page 1 of 3 [1] 2 3 Next page →
| From | Jonas Thörnvall <jonas.thornvall@gmail.com> |
|---|---|
| Date | 2019-08-08 16:50 -0700 |
| Subject | Is the input type ID passed as a parameter onChange? If not how can i achieve it. |
| Message-ID | <7289e763-fc8c-4686-8f68-12094ee06440@googlegroups.com> |
<input type="range" onChange="korgvol()" id="korgvol1" min="0" max="127" orient="vertical"/> Well i guess it is not, korgvol() will not know it was called from korgvol1? Following scenario there is 16 channels with volume controls "midi control and steer digital mixer". It would be weird to create a vol function for each channel would it not, but if korgvol does not know the ID that called it, what to do? Ideally the ID would be a parameter of the function call? Or?
[toc] | [next] | [standalone]
| From | Jonas Thörnvall <jonas.thornvall@gmail.com> |
|---|---|
| Date | 2019-08-08 16:55 -0700 |
| Message-ID | <d9f9cbf1-cf2b-47d5-b1e9-9d3d9fa811bf@googlegroups.com> |
| In reply to | #37061 |
Den fredag 9 augusti 2019 kl. 01:50:13 UTC+2 skrev Jonas Thörnvall: > <input type="range" onChange="korgvol()" id="korgvol1" min="0" max="127" orient="vertical"/> > > Well i guess it is not, korgvol() will not know it was called from korgvol1? > > Following scenario there is 16 channels with volume controls "midi control and steer digital mixer". > > It would be weird to create a vol function for each channel would it not, but if korgvol does not know the ID that called it, what to do? Ideally the ID would be a parameter of the function call? > > Or? A short yes or no will do so i know if i have to make 16 volume functions? Well i just thought of a solution it is to read in, set and send all channel volume values everytime a single channel change. It is not beautiful though. I do know it is a question for w3 rather then Javascript, but it seem important.
[toc] | [prev] | [next] | [standalone]
| From | "Michael Haufe (TNO)" <tno@thenewobjective.com> |
|---|---|
| Date | 2019-08-09 00:16 -0700 |
| Message-ID | <7fc94d37-a44c-43a0-bb81-b9116f9d20fa@googlegroups.com> |
| In reply to | #37061 |
On Thursday, August 8, 2019 at 6:50:13 PM UTC-5, Jonas Thörnvall wrote:
> <input type="range" onChange="korgvol()" id="korgvol1" min="0" max="127" orient="vertical"/>
>
> Well i guess it is not, korgvol() will not know it was called from korgvol1?
>
> Following scenario there is 16 channels with volume controls "midi control and steer digital mixer".
>
> It would be weird to create a vol function for each channel would it not, but if korgvol does not know the ID that called it, what to do? Ideally the ID would be a parameter of the function call?
>
> Or?
You'll want something like this:
<script>
class Channel {
constructor(el) {
this.el = el
el.addEventListener('change', this.onChange.bind(this))
el.addEventListener('input', this.onInput.bind(this))
}
// continuous change
onInput(e) {
console.log(`${e.target.name}:${e.target.value}`)
}
// fires once after change
onChange(e) {
console.log(`${e.target.name}:${e.target.value}`)
}
}
// get started
document.addEventListener('DOMContentLoaded',() => {
let channels = Array.from(document.querySelectorAll('.channel'),(c) => new Channel(c))
// etc
})
</script>
A demo:
<https://codepen.io/mlhaufe/pen/eqjZGr>
[toc] | [prev] | [next] | [standalone]
| From | Julio Di Egidio <julio@diegidio.name> |
|---|---|
| Date | 2019-08-09 00:46 -0700 |
| Message-ID | <0c7e3cae-3c01-4ca8-a2e9-db004a2de1b8@googlegroups.com> |
| In reply to | #37064 |
On Friday, 9 August 2019 09:16:10 UTC+2, Michael Haufe (TNO) wrote:
> On Thursday, August 8, 2019 at 6:50:13 PM UTC-5, Jonas Thörnvall wrote:
> > <input type="range" onChange="korgvol()" id="korgvol1" min="0" max="127" orient="vertical"/>
> >
> > Well i guess it is not, korgvol() will not know it was called from korgvol1?
> >
> > Following scenario there is 16 channels with volume controls "midi control and steer digital mixer".
> >
> > It would be weird to create a vol function for each channel would it not, but if korgvol does not know the ID that called it, what to do? Ideally the ID would be a parameter of the function call?
> >
> > Or?
>
> You'll want something like this:
>
> <script>
> class Channel {
> constructor(el) {
> this.el = el
> el.addEventListener('change', this.onChange.bind(this))
> el.addEventListener('input', this.onInput.bind(this))
> }
> // continuous change
> onInput(e) {
> console.log(`${e.target.name}:${e.target.value}`)
> }
> // fires once after change
> onChange(e) {
> console.log(`${e.target.name}:${e.target.value}`)
> }
> }
>
> // get started
> document.addEventListener('DOMContentLoaded',() => {
> let channels = Array.from(document.querySelectorAll('.channel'),(c) => new Channel(c))
>
> // etc
> })
> </script>
>
> A demo:
>
> <https://codepen.io/mlhaufe/pen/eqjZGr>
<button id="myId" onclick="alert(this.id)">Click me</button>
RTFM.
Julio
[toc] | [prev] | [next] | [standalone]
| From | Jonas Thörnvall <jonas.thornvall@gmail.com> |
|---|---|
| Date | 2019-08-10 02:03 -0700 |
| Message-ID | <6f06a616-8c91-4e6e-8e60-6cbd9b59de63@googlegroups.com> |
| In reply to | #37065 |
Den fredag 9 augusti 2019 kl. 09:46:54 UTC+2 skrev Julio Di Egidio:
> On Friday, 9 August 2019 09:16:10 UTC+2, Michael Haufe (TNO) wrote:
> > On Thursday, August 8, 2019 at 6:50:13 PM UTC-5, Jonas Thörnvall wrote:
> > > <input type="range" onChange="korgvol()" id="korgvol1" min="0" max="127" orient="vertical"/>
> > >
> > > Well i guess it is not, korgvol() will not know it was called from korgvol1?
> > >
> > > Following scenario there is 16 channels with volume controls "midi control and steer digital mixer".
> > >
> > > It would be weird to create a vol function for each channel would it not, but if korgvol does not know the ID that called it, what to do? Ideally the ID would be a parameter of the function call?
> > >
> > > Or?
> >
> > You'll want something like this:
> >
> > <script>
> > class Channel {
> > constructor(el) {
> > this.el = el
> > el.addEventListener('change', this.onChange.bind(this))
> > el.addEventListener('input', this.onInput.bind(this))
> > }
> > // continuous change
> > onInput(e) {
> > console.log(`${e.target.name}:${e.target.value}`)
> > }
> > // fires once after change
> > onChange(e) {
> > console.log(`${e.target.name}:${e.target.value}`)
> > }
> > }
> >
> > // get started
> > document.addEventListener('DOMContentLoaded',() => {
> > let channels = Array.from(document.querySelectorAll('.channel'),(c) => new Channel(c))
> >
> > // etc
> > })
> > </script>
> >
> > A demo:
> >
> > <https://codepen.io/mlhaufe/pen/eqjZGr>
>
> <button id="myId" onclick="alert(this.id)">Click me</button>
>
> RTFM.
>
> Julio
This or that, well i am happy it is passed with this thanks, Julio!
It seem i can make a Javascript controlsurface that will reach all functionality on my digital mixer, because it all can be set over midi.
Nice, because the interfaces of early 90's electronic was shit. "Well maybe a bit due to lack of space" but with a control surface that is no longer a problem.
[toc] | [prev] | [next] | [standalone]
| From | "Evertjan." <exxjxw.hannivoort@inter.nl.net> |
|---|---|
| Date | 2019-08-10 11:12 +0200 |
| Message-ID | <XnsAAA771F0C36A0eejj99@194.109.6.166> |
| In reply to | #37074 |
<jonas.thornvall@gmail.com> wrote on 10 Aug 2019 in comp.lang.javascript: > This or that, well i am happy it is passed with this thanks, Julio! > > It seem i can make a Javascript controlsurface that will reach all > functionality on my digital mixer, because it all can be set over midi. > > Nice, because the interfaces of early 90's electronic was shit. "Well > maybe a bit due to lack of space" but with a control surface that is no > longer a problem. Eh? Remember to wax all controlsurfaces now and then. Your path could be slippery, when wet. -- Evertjan. The Netherlands. (Please change the x'es to dots in my emailaddress)
[toc] | [prev] | [next] | [standalone]
| From | Jonas Thörnvall <jonas.thornvall@gmail.com> |
|---|---|
| Date | 2019-08-10 02:08 -0700 |
| Message-ID | <a0e41c4b-b8bb-47bc-ad7b-af4db6447a87@googlegroups.com> |
| In reply to | #37065 |
Den fredag 9 augusti 2019 kl. 09:46:54 UTC+2 skrev Julio Di Egidio:
> On Friday, 9 August 2019 09:16:10 UTC+2, Michael Haufe (TNO) wrote:
> > On Thursday, August 8, 2019 at 6:50:13 PM UTC-5, Jonas Thörnvall wrote:
> > > <input type="range" onChange="korgvol()" id="korgvol1" min="0" max="127" orient="vertical"/>
> > >
> > > Well i guess it is not, korgvol() will not know it was called from korgvol1?
> > >
> > > Following scenario there is 16 channels with volume controls "midi control and steer digital mixer".
> > >
> > > It would be weird to create a vol function for each channel would it not, but if korgvol does not know the ID that called it, what to do? Ideally the ID would be a parameter of the function call?
> > >
> > > Or?
> >
> > You'll want something like this:
> >
> > <script>
> > class Channel {
> > constructor(el) {
> > this.el = el
> > el.addEventListener('change', this.onChange.bind(this))
> > el.addEventListener('input', this.onInput.bind(this))
> > }
> > // continuous change
> > onInput(e) {
> > console.log(`${e.target.name}:${e.target.value}`)
> > }
> > // fires once after change
> > onChange(e) {
> > console.log(`${e.target.name}:${e.target.value}`)
> > }
> > }
> >
> > // get started
> > document.addEventListener('DOMContentLoaded',() => {
> > let channels = Array.from(document.querySelectorAll('.channel'),(c) => new Channel(c))
> >
> > // etc
> > })
> > </script>
> >
> > A demo:
> >
> > <https://codepen.io/mlhaufe/pen/eqjZGr>
>
> <button id="myId" onclick="alert(this.id)">Click me</button>
>
> RTFM.
>
> Julio
Honestly i think you would be hardpressed to find the manual page for that one. I could find it answered using Google but "only if you knew" that the parameter passed was "this.id".
It would been more natural with "korgvol(korgvol1)" but that is just an opinion.
[toc] | [prev] | [next] | [standalone]
| From | Julio Di Egidio <julio@diegidio.name> |
|---|---|
| Date | 2019-08-10 03:14 -0700 |
| Message-ID | <b57ec9b5-1fd0-4aab-9cf6-5304433677c2@googlegroups.com> |
| In reply to | #37075 |
On Saturday, 10 August 2019 11:09:02 UTC+2, Jonas Thörnvall wrote:
> Den fredag 9 augusti 2019 kl. 09:46:54 UTC+2 skrev Julio Di Egidio:
<snip>
> > <button id="myId" onclick="alert(this.id)">Click me</button>
> >
> > RTFM.
>
> Honestly i think you would be hardpressed to find the manual page for that one. I could find it answered using Google but "only if you knew" that the parameter passed was "this.id".
You miss the point: you should to read "the manual" *before* you get
seriously involved with any language (or technology, or platform, etc.).
Last year I learned Python: I went through a couple of tutorials, then the
main guide, finally a quick look across the reference documentation. Well,
Python is a relatively simple language and I am quite an expert programmer,
anyway in some half a day I was done and now I know Python. Not that I
remember all the details by heart, also as I haven't used it much since,
but I do remember: the philosophy underlying the language and the approach
to implementation in that language, as well as the overall capabilities,
and I can certainly find my way through the documentation if I need anything
specific.
I have been doing that for all languages I have learned across my career,
and not just I: that is how professional programmers work, the opposite of
proceeding by trial and error.
So the point is not that you struggle with something then look it up and
find a page in the manual that deals exactly with that: no, you first
study the language, then just know what to look for... (at least
essentially.)
Back to JavaScript:
As for your specific problem, here is a relevant page (read to the bottom):
<https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/this>
And that's a topic so fundamental that, as a JS programmer, you are actually
expected to know about the this reference almost by heart, at least what
you do use.
But, back to the main issue, here is what you should really read once and for
all, and then you can start "programming in JS":
<https://developer.mozilla.org/en-US/docs/Web/JavaScript>
(I'd say get at least 2-3 levels deep through the links).
> It would been more natural with "korgvol(korgvol1)" but that is just an opinion.
That's called "hard-coding things" and it's a no no.
E.g. "alert(this.id)" you can copy-paste into any inline handler and it'll
just work, it is "abstract" enough: if you instead hard-code that id, you'll
have to put and keep the right id everywhere by hand...
That said, get your head around nested quotes: you could do that, just an
id is a string: "korgvol('korgvol1')". Without quotes, it's interpreted
as an identifier, and of course you get an error of the sort object is
undefined.
HTH, and if you liked it you can send a donation to the Bitcoin address
in my signature.
Julio
[toc] | [prev] | [next] | [standalone]
| From | Jonas Thörnvall <jonas.thornvall@gmail.com> |
|---|---|
| Date | 2019-08-10 16:32 -0700 |
| Message-ID | <05dbfbb6-648f-4cbf-89e6-7fb1d1e3b44e@googlegroups.com> |
| In reply to | #37078 |
Den lördag 10 augusti 2019 kl. 12:14:06 UTC+2 skrev Julio Di Egidio:
> On Saturday, 10 August 2019 11:09:02 UTC+2, Jonas Thörnvall wrote:
> > Den fredag 9 augusti 2019 kl. 09:46:54 UTC+2 skrev Julio Di Egidio:
> <snip>
> > > <button id="myId" onclick="alert(this.id)">Click me</button>
> > >
> > > RTFM.
> >
> > Honestly i think you would be hardpressed to find the manual page for that one. I could find it answered using Google but "only if you knew" that the parameter passed was "this.id".
>
> You miss the point: you should to read "the manual" *before* you get
> seriously involved with any language (or technology, or platform, etc.).
>
> Last year I learned Python: I went through a couple of tutorials, then the
> main guide, finally a quick look across the reference documentation. Well,
> Python is a relatively simple language and I am quite an expert programmer,
> anyway in some half a day I was done and now I know Python. Not that I
> remember all the details by heart, also as I haven't used it much since,
> but I do remember: the philosophy underlying the language and the approach
> to implementation in that language, as well as the overall capabilities,
> and I can certainly find my way through the documentation if I need anything
> specific.
>
> I have been doing that for all languages I have learned across my career,
> and not just I: that is how professional programmers work, the opposite of
> proceeding by trial and error.
>
> So the point is not that you struggle with something then look it up and
> find a page in the manual that deals exactly with that: no, you first
> study the language, then just know what to look for... (at least
> essentially.)
>
> Back to JavaScript:
>
> As for your specific problem, here is a relevant page (read to the bottom):
> <https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/this>
> And that's a topic so fundamental that, as a JS programmer, you are actually
> expected to know about the this reference almost by heart, at least what
> you do use.
>
> But, back to the main issue, here is what you should really read once and for
> all, and then you can start "programming in JS":
> <https://developer.mozilla.org/en-US/docs/Web/JavaScript>
> (I'd say get at least 2-3 levels deep through the links).
>
> > It would been more natural with "korgvol(korgvol1)" but that is just an opinion.
>
> That's called "hard-coding things" and it's a no no.
>
> E.g. "alert(this.id)" you can copy-paste into any inline handler and it'll
> just work, it is "abstract" enough: if you instead hard-code that id, you'll
> have to put and keep the right id everywhere by hand...
>
> That said, get your head around nested quotes: you could do that, just an
> id is a string: "korgvol('korgvol1')". Without quotes, it's interpreted
> as an identifier, and of course you get an error of the sort object is
> undefined.
>
> HTH, and if you liked it you can send a donation to the Bitcoin address
> in my signature.
>
> Julio
If this.id containd the idput id, why can't i reach the id from script?
function korgvol(){
if(this.id=="korgvol1") {CCtype=0}
else if (this.id=="korgvol2") {CCtype=1}
else if (this.id=="korgvol3") {CCtype=2}
else if (this.id=="korgvol4") {CCtype=3}
else if (this.id=="korgvol5") {CCtype=4}
else if (this.id=="korgvol6") {CCtype=5}
else if (this.id=="korgvol7") {CCtype=6}
else if (this.id=="korgvol8") {CCtype=7}
else if (this.id=="korgvol9") {CCtype=8}
else if (this.id=="korgvol10") {CCtype=9}
else if (this.id=="korgvol11") {CCtype=10}
else if (this.id=="korgvol12") {CCtype=11}
else if (this.id=="korgvol13") {CCtype=12}
else if (this.id=="korgvol14") {CCtype=13}
else if (this.id=="korgvol15") {CCtype=14}
else if (this.id=="korgvol16") {CCtype=15}
CCchan=176+channelTRX-1;
//Can't reach the value of the id below, why?
//I get can't read property value of null?
CCVol=document.getElementById(this.id").value;
settingChange=[CCchan,CCtype,CCvol];
outportarr[outportindex].send(settingChange);
}
[toc] | [prev] | [next] | [standalone]
| From | Jonas Thörnvall <jonas.thornvall@gmail.com> |
|---|---|
| Date | 2019-08-10 16:36 -0700 |
| Message-ID | <f8091e26-062a-4aa6-bb2e-1910c565017b@googlegroups.com> |
| In reply to | #37081 |
Den söndag 11 augusti 2019 kl. 01:32:10 UTC+2 skrev Jonas Thörnvall:
> Den lördag 10 augusti 2019 kl. 12:14:06 UTC+2 skrev Julio Di Egidio:
> > On Saturday, 10 August 2019 11:09:02 UTC+2, Jonas Thörnvall wrote:
> > > Den fredag 9 augusti 2019 kl. 09:46:54 UTC+2 skrev Julio Di Egidio:
> > <snip>
> > > > <button id="myId" onclick="alert(this.id)">Click me</button>
> > > >
> > > > RTFM.
> > >
> > > Honestly i think you would be hardpressed to find the manual page for that one. I could find it answered using Google but "only if you knew" that the parameter passed was "this.id".
> >
> > You miss the point: you should to read "the manual" *before* you get
> > seriously involved with any language (or technology, or platform, etc.).
> >
> > Last year I learned Python: I went through a couple of tutorials, then the
> > main guide, finally a quick look across the reference documentation. Well,
> > Python is a relatively simple language and I am quite an expert programmer,
> > anyway in some half a day I was done and now I know Python. Not that I
> > remember all the details by heart, also as I haven't used it much since,
> > but I do remember: the philosophy underlying the language and the approach
> > to implementation in that language, as well as the overall capabilities,
> > and I can certainly find my way through the documentation if I need anything
> > specific.
> >
> > I have been doing that for all languages I have learned across my career,
> > and not just I: that is how professional programmers work, the opposite of
> > proceeding by trial and error.
> >
> > So the point is not that you struggle with something then look it up and
> > find a page in the manual that deals exactly with that: no, you first
> > study the language, then just know what to look for... (at least
> > essentially.)
> >
> > Back to JavaScript:
> >
> > As for your specific problem, here is a relevant page (read to the bottom):
> > <https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/this>
> > And that's a topic so fundamental that, as a JS programmer, you are actually
> > expected to know about the this reference almost by heart, at least what
> > you do use.
> >
> > But, back to the main issue, here is what you should really read once and for
> > all, and then you can start "programming in JS":
> > <https://developer.mozilla.org/en-US/docs/Web/JavaScript>
> > (I'd say get at least 2-3 levels deep through the links).
> >
> > > It would been more natural with "korgvol(korgvol1)" but that is just an opinion.
> >
> > That's called "hard-coding things" and it's a no no.
> >
> > E.g. "alert(this.id)" you can copy-paste into any inline handler and it'll
> > just work, it is "abstract" enough: if you instead hard-code that id, you'll
> > have to put and keep the right id everywhere by hand...
> >
> > That said, get your head around nested quotes: you could do that, just an
> > id is a string: "korgvol('korgvol1')". Without quotes, it's interpreted
> > as an identifier, and of course you get an error of the sort object is
> > undefined.
> >
> > HTH, and if you liked it you can send a donation to the Bitcoin address
> > in my signature.
> >
> > Julio
>
> If this.id containd the idput id, why can't i reach the id from script?
>
> function korgvol(){
>
> if(this.id=="korgvol1") {CCtype=0}
> else if (this.id=="korgvol2") {CCtype=1}
> else if (this.id=="korgvol3") {CCtype=2}
> else if (this.id=="korgvol4") {CCtype=3}
> else if (this.id=="korgvol5") {CCtype=4}
> else if (this.id=="korgvol6") {CCtype=5}
> else if (this.id=="korgvol7") {CCtype=6}
> else if (this.id=="korgvol8") {CCtype=7}
> else if (this.id=="korgvol9") {CCtype=8}
> else if (this.id=="korgvol10") {CCtype=9}
> else if (this.id=="korgvol11") {CCtype=10}
> else if (this.id=="korgvol12") {CCtype=11}
> else if (this.id=="korgvol13") {CCtype=12}
> else if (this.id=="korgvol14") {CCtype=13}
> else if (this.id=="korgvol15") {CCtype=14}
> else if (this.id=="korgvol16") {CCtype=15}
>
> CCchan=176+channelTRX-1;
>
> //Can't reach the value of the id below, why?
> //I get can't read property value of null?
>
> CCVol=document.getElementById(this.id").value;
> settingChange=[CCchan,CCtype,CCvol];
> outportarr[outportindex].send(settingChange);
> }
This is the function calls, via HTML
<td valign=bottom align=middle> <B>VOLUME</B><BR><input type="range" onChange="korgvol(this.id)" id="korgvol1" min="0" max="127" orient="vertical"/></td>
<td valign=bottom align=middle> <B>VOLUME</B><BR><input type="range" onChange="korgvol(this.id)" id="korgvol2" min="0" max="127" orient="vertical"/></td>
<td valign=bottom align=middle> <B>VOLUME</B><BR><input type="range" onChange="korgvol(this.id)" id="korgvol3" min="0" max="127" orient="vertical"/></td>
<td valign=bottom align=middle> <B>VOLUME</B><BR><input type="range" onChange="korgvol(this.id)" id="korgvol4" min="0" max="127" orient="vertical"/></td>
<td valign=bottom align=middle> <B>VOLUME</B><BR><input type="range" onChange="korgvol(this.id)" id="korgvol5" min="0" max="127" orient="vertical"/></td>
<td valign=bottom align=middle> <B>VOLUME</B><BR><input type="range" onChange="korgvol(this.id)" id="korgvol6" min="0" max="127" orient="vertical"/></td>
<td valign=bottom align=middle> <B>VOLUME</B><BR><input type="range" onChange="korgvol(this.id)" id="korgvol7" min="0" max="127" orient="vertical"/></td>
<td valign=bottom align=middle> <B>VOLUME</B><BR><input type="range" onChange="korgvol(this.id)" id="korgvol8" min="0" max="127" orient="vertical"/></td>
<td valign=bottom align=middle> <B>VOLUME</B><BR><input type="range" onChange="korgvol(this.id)" id="korgvol9" min="0" max="127" orient="vertical"/></td>
<td valign=bottom align=middle> <B>VOLUME</B><BR><input type="range" onChange="korgvol(this.id)" id="korgvol10" min="0" max="127" orient="vertical"/></td>
<td valign=bottom align=middle> <B>VOLUME</B><BR><input type="range" onChange="korgvol(this.id)" id="korgvol11" min="0" max="127" orient="vertical"/></td>
<td valign=bottom align=middle> <B>VOLUME</B><BR><input type="range" onChange="korgvol(this.id)" id="korgvol12" min="0" max="127" orient="vertical"/></td>
<td valign=bottom align=middle> <B>VOLUME</B><BR><input type="range" onChange="korgvol(this.id)" id="korgvol13" min="0" max="127" orient="vertical"/></td>
<td valign=bottom align=middle> <B>VOLUME</B><BR><input type="range" onChange="korgvol(this.id)" id="korgvol14" min="0" max="127" orient="vertical"/></td>
<td valign=bottom align=middle> <B>VOLUME</B><BR><input type="range" onChange="korgvol(this.id)" id="korgvol15" min="0" max="127" orient="vertical"/></td>
<td valign=bottom align=middle> <B>VOLUME</B><BR><input type="range" onChange="korgvol(this.id)" id="korgvol16" min="0" max="127" orient="vertical"/></td>
[toc] | [prev] | [next] | [standalone]
| From | dr.j.r.stockton@gmail.com |
|---|---|
| Date | 2019-08-11 01:39 -0700 |
| Message-ID | <25a5b812-2599-492a-856c-b052f9024d4d@googlegroups.com> |
| In reply to | #37081 |
On Sunday, 11 August 2019 00:32:10 UTC+1, Jonas Thörnvall wrote:
> if(this.id=="korgvol1") {CCtype=0}
> else if (this.id=="korgvol2") {CCtype=1}
> else if (this.id=="korgvol3") {CCtype=2}
> else if (this.id=="korgvol4") {CCtype=3}
> else if (this.id=="korgvol5") {CCtype=4}
> else if (this.id=="korgvol6") {CCtype=5}
> else if (this.id=="korgvol7") {CCtype=6}
> else if (this.id=="korgvol8") {CCtype=7}
> else if (this.id=="korgvol9") {CCtype=8}
> else if (this.id=="korgvol10") {CCtype=9}
> else if (this.id=="korgvol11") {CCtype=10}
> else if (this.id=="korgvol12") {CCtype=11}
> else if (this.id=="korgvol13") {CCtype=12}
> else if (this.id=="korgvol14") {CCtype=13}
> else if (this.id=="korgvol15") {CCtype=14}
> else if (this.id=="korgvol16") {CCtype=15}
More briefly, something like
CCtype = this.id.substring(7) -1
would save keystrokes.
--
(c) John Stockton, near London, UK. Using Google Groups. |
Mail: J.R.""""""""@physics.org - or as Reply-To, if any. |
[toc] | [prev] | [next] | [standalone]
| From | Jonas Thörnvall <jonas.thornvall@gmail.com> |
|---|---|
| Date | 2019-08-11 02:38 -0700 |
| Message-ID | <26c701d7-cb23-44f2-9ca2-b4c30b888030@googlegroups.com> |
| In reply to | #37085 |
Den söndag 11 augusti 2019 kl. 10:39:32 UTC+2 skrev dr.j.r...@gmail.com:
> On Sunday, 11 August 2019 00:32:10 UTC+1, Jonas Thörnvall wrote:
>
> > if(this.id=="korgvol1") {CCtype=0}
> > else if (this.id=="korgvol2") {CCtype=1}
> > else if (this.id=="korgvol3") {CCtype=2}
> > else if (this.id=="korgvol4") {CCtype=3}
> > else if (this.id=="korgvol5") {CCtype=4}
> > else if (this.id=="korgvol6") {CCtype=5}
> > else if (this.id=="korgvol7") {CCtype=6}
> > else if (this.id=="korgvol8") {CCtype=7}
> > else if (this.id=="korgvol9") {CCtype=8}
> > else if (this.id=="korgvol10") {CCtype=9}
> > else if (this.id=="korgvol11") {CCtype=10}
> > else if (this.id=="korgvol12") {CCtype=11}
> > else if (this.id=="korgvol13") {CCtype=12}
> > else if (this.id=="korgvol14") {CCtype=13}
> > else if (this.id=="korgvol15") {CCtype=14}
> > else if (this.id=="korgvol16") {CCtype=15}
>
> More briefly, something like
> CCtype = this.id.substring(7) -1
> would save keystrokes.
>
> --
> (c) John Stockton, near London, UK. Using Google Groups. |
> Mail: J.R.""""""""@physics.org - or as Reply-To, if any. |
Yeah you are correct, i was thinking about similar, but then i thought it would be abit hard to read. And really i just copy paste lines and change a digit or two.
[toc] | [prev] | [next] | [standalone]
| From | "Evertjan." <exxjxw.hannivoort@inter.nl.net> |
|---|---|
| Date | 2019-08-11 11:58 +0200 |
| Subject | NEVER use "this" as a variable Re: Is the input type ID passed as a parameter onChange? If not how can i achieve it. |
| Message-ID | <XnsAAA879E54D98Ceejj99@194.109.6.166> |
| In reply to | #37086 |
=?UTF-8?Q?Jonas_Th=C3=B6rnvall?= <jonas.thornvall@gmail.com> wrote on 11
Aug 2019 in comp.lang.javascript:
> Den söndag 11 augusti 2019 kl. 10:39:32 UTC+2 skrev
> dr.j.r...@gmail.com:
>> On Sunday, 11 August 2019 00:32:10 UTC+1, Jonas Thörnvall wrote:
>>
>> > if(this.id=="korgvol1") {CCtype=0}
>> > else if (this.id=="korgvol2") {CCtype=1}
>> > else if (this.id=="korgvol3") {CCtype=2}
>> > else if (this.id=="korgvol4") {CCtype=3}
>> > else if (this.id=="korgvol5") {CCtype=4}
>> > else if (this.id=="korgvol6") {CCtype=5}
>> > else if (this.id=="korgvol7") {CCtype=6}
>> > else if (this.id=="korgvol8") {CCtype=7}
>> > else if (this.id=="korgvol9") {CCtype=8}
>> > else if (this.id=="korgvol10") {CCtype=9}
>> > else if (this.id=="korgvol11") {CCtype=10}
>> > else if (this.id=="korgvol12") {CCtype=11}
>> > else if (this.id=="korgvol13") {CCtype=12}
>> > else if (this.id=="korgvol14") {CCtype=13}
>> > else if (this.id=="korgvol15") {CCtype=14}
>> > else if (this.id=="korgvol16") {CCtype=15}
>>
>> More briefly, something like
>> CCtype = this.id.substring(7) -1
>> would save keystrokes.
>>
>> --
>> (c) John Stockton, near London, UK. Using Google Groups. |
>> Mail: J.R.""""""""@physics.org - or as Reply-To, if any. |
>
> Yeah you are correct, i was thinking about similar, but then i thought
> it would be abit hard to read. And really i just copy paste lines and
> change a digit or two.
The computer has no problem with that,
though it is endearing that you care.
If you make the id more conform in length,
like
id = "korgvol002"
then the js is maybe more readable:
CCtype = this.id.replace('korgvol','') - 1;
[the - 1 does an automagic typeconversion to numeric too]
HOWEVER:
you should NEVER use "this" as a variable
in the receiving function:
function korgvol(this) {
if (this.id=="korgvol2") {CCtype=1}}
};
but:
function korgvol(myThis) {
if (myThis.id=="korgvol2") {CCtype=1}}
};
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
[toc] | [prev] | [next] | [standalone]
| From | "R.Wieser" <address@not.available> |
|---|---|
| Date | 2019-08-11 12:13 +0200 |
| Subject | Re: NEVER use "this" as a variable Re: Is the input type ID passed as a parameter onChange? If not how can i achieve it. |
| Message-ID | <qiopp9$1lea$1@gioia.aioe.org> |
| In reply to | #37087 |
Evertjan, > you should NEVER use "this" as a variable > in the receiving function: Its good that you want to warn about wrong/risky usage, but please do add an explanation. Without it the warning itself wil most likely be forgotten rather quickly (I know it does with me). And yes, I'm interrested. What makes "this" so special that you should not use it as a (local!) argument variable there ? Regards, Rudy Wieser
[toc] | [prev] | [next] | [standalone]
| From | "Evertjan." <exxjxw.hannivoort@inter.nl.net> |
|---|---|
| Date | 2019-08-11 12:31 +0200 |
| Subject | Re: NEVER use "this" as a variable Re: Is the input type ID passed as a parameter onChange? If not how can i achieve it. |
| Message-ID | <XnsAAA87F5529C5eejj99@194.109.6.166> |
| In reply to | #37089 |
"R.Wieser" <address@not.available> wrote on 11 Aug 2019 in
comp.lang.javascript:
>> you should NEVER use "this" as a variable
>> in the receiving function:
>
> Its good that you want to warn about wrong/risky usage, but please do
> add an explanation. Without it the warning itself wil most likely be
> forgotten rather quickly (I know it does with me).
Panta rhei, kai ouden menei.
> And yes, I'm interrested. What makes "this" so special that you should
> not use it as a (local!) argument variable there ?
Because
function korgvol(that) {
if (this.id=="korgvol2") {CCtype=1}}
};
would maybe be quite legal,
but difficult to debug where not meant.
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
[toc] | [prev] | [next] | [standalone]
| From | "R.Wieser" <address@not.available> |
|---|---|
| Date | 2019-08-11 20:15 +0200 |
| Subject | Re: NEVER use "this" as a variable Re: Is the input type ID passed as a parameter onChange? If not how can i achieve it. |
| Message-ID | <qipma0$1j4v$1@gioia.aioe.org> |
| In reply to | #37090 |
Evertjan,
> Because
>
> function korgvol(that) {
> if (this.id=="korgvol2") {CCtype=1}}
> };
>
> would maybe be quite legal,
> but difficult to debug where not meant.
So, the same problem as
that = ...
...
function korgvol(this) {
if (that.id=="korgvol2") {CCtype=1}}
};
Not about the "this" variable per se.
Regards,
Rudy Wieser
[toc] | [prev] | [next] | [standalone]
| From | Arno Welzel <usenet@arnowelzel.de> |
|---|---|
| Date | 2019-08-11 17:50 +0200 |
| Subject | Re: NEVER use "this" as a variable Re: Is the input type ID passed as a parameter onChange? If not how can i achieve it. |
| Message-ID | <grarq0FaqaoU3@mid.individual.net> |
| In reply to | #37089 |
R.Wieser: > Evertjan, > >> you should NEVER use "this" as a variable >> in the receiving function: > > Its good that you want to warn about wrong/risky usage, but please do add an > explanation. Without it the warning itself wil most likely be forgotten > rather quickly (I know it does with me). "this" is a keyword with a special meaning. > And yes, I'm interrested. What makes "this" so special that you should not > use it as a (local!) argument variable there ? <https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/this> -- Arno Welzel https://arnowelzel.de
[toc] | [prev] | [next] | [standalone]
| From | "R.Wieser" <address@not.available> |
|---|---|
| Date | 2019-08-11 20:20 +0200 |
| Subject | Re: NEVER use "this" as a variable Re: Is the input type ID passed as a parameter onChange? If not how can i achieve it. |
| Message-ID | <qipma1$1j4v$2@gioia.aioe.org> |
| In reply to | #37094 |
Arno, > "this" is a keyword with a special meaning. I know. So, how could it be problematic in the posted code ? Do you have an example ? > <https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/this> I'm sorry, too much info and not yet enough knowledge to be able to pick the example problem from it all. Regards, Rudy Wieser
[toc] | [prev] | [next] | [standalone]
| From | dr.j.r.stockton@gmail.com |
|---|---|
| Date | 2019-08-11 13:54 -0700 |
| Subject | Re: NEVER use "this" as a variable Re: Is the input type ID passed as a parameter onChange? If not how can i achieve it. |
| Message-ID | <ab58d882-01b8-456c-bc8e-f066bdd36068@googlegroups.com> |
| In reply to | #37097 |
On Sunday, 11 August 2019 19:20:55 UTC+1, R.Wieser wrote: > > "this" is a keyword with a special meaning. > > I know. So, how could it be problematic in the posted code ? Do you have > an example ? An author must express things so that the compiler will understand as intended. But it is well to express them so that the author will immediately understand, perhaps many months later - and that means not using any "word"s that are special in the language in a manner other than that presumably intended. To that end, if I have a function with an argument that, on call, will usually be provided with a ".this" value, I don't call it "this" within the function. I might call it "This" or "THIS"; but having learned Latin (twice) several decades ago, I tend to call it "HIC" - and, rightly or wrongly, "HOC" for "that". -- (c) John Stockton, near London, UK. Using Google Groups. | Mail: J.R.""""""""@physics.org - or as Reply-To, if any. |
[toc] | [prev] | [next] | [standalone]
| From | "R.Wieser" <address@not.available> |
|---|---|
| Date | 2019-08-12 08:48 +0200 |
| Subject | Re: NEVER use "this" as a variable Re: Is the input type ID passed as a parameter onChange? If not how can i achieve it. |
| Message-ID | <qir24f$1dj7$1@gioia.aioe.org> |
| In reply to | #37098 |
John, > An author must express things so that the compiler will > understand as intended. In that case, using "this" as a function argument should not be a problem. > But it is well to express them so that the author will > immediately understand, perhaps many months later > - and that means not using any "word"s that are special > in the language in a manner other than that presumably > intended. I understand that part too (I've been "at it" for a few decades myself). Its also why I posted my own example - by comparing I'm trying to get a finger behind the reasoning for your warning.. > and that means not using any "word"s that are special in > the language in a manner other than that presumably > intended. In my example I've /made/ a word special, by defining it as a non-local (global) variable - possibly containing a reference to an object too. In our examples, what makes yours more problematic than mine ? I do not see it, as the very same problem could, as far as I can see, occur in both ... Regards, Rudy Wieser P.s. Should a programmer be allowed to use "this" in a callback function like that ? Which object w|should it refer to ?
[toc] | [prev] | [next] | [standalone]
Page 1 of 3 [1] 2 3 Next page →
Back to top | Article view | comp.lang.javascript
csiph-web