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


Groups > comp.lang.javascript > #35862

Re: Adding extra element "to option list" using next loop?

Newsgroups comp.lang.javascript
Subject Re: Adding extra element "to option list" using next loop?
From "Evertjan." <exxjxw.hannivoort@inter.nl.net>
References <b1c258f0-0654-4352-ba33-6795f556807f@googlegroups.com> <c1f92b60-9792-489e-8016-3610d1e5d67b@googlegroups.com> <XnsA9A6853F0457Aeejj99@194.109.6.166> <57b35f6e-e4e9-453e-932c-b0f692fb1ba2@googlegroups.com> <ptj2rc$v42$1@dont-email.me>
Date 2018-11-27 12:08 +0100
Message-ID <XnsA9A77B7C81530eejj99@194.109.6.166> (permalink)

Show all headers | View raw


Jake Jarvis <pig_in_shoes@yahoo.com> wrote on 27 Nov 2018 in
comp.lang.javascript: 

> Am 27.11.2018 um 07:45 schrieb Jonas Thörnvall:
>> Den måndag 26 november 2018 kl. 13:05:57 UTC+1 skrev Evertjan.:
>>> =?UTF-8?Q?Jonas_Th=C3=B6rnvall?= <jonas.thornvall@gmail.com> wrote on
>>> 26 Nov 2018 in comp.lang.javascript:
>>>
>>>> Den lördag 24 november 2018 kl. 09:40:40 UTC+1 skrev Jonas
>>>> Thörnvall: 
>>>>> I have a hard time understand the intrisic works of next loops, i
>>>>> use exa
>>>> mples i found on net onto create an optionlist of "devices".
>>>>>
>>>>> But i want to add an extra "option to the list of my own", but since
>>>>> i do
>>>>   not understand the inner works of next loop, i am a bit stumped
>>>>   howto add my extra alternative to the option list. Here i try to
>>>>   add it before, and i also tried after. But i do not know howto
>>>>   position myself relative the next loop?
>>>>>
>>>>> Could someone please show me?
>>>>>
>>>>>    var optout = document.createElement("option");
>>>>>    optout.text = "WEB SF2 SYNTH MY ADDED ADDED ALTERNATIVE";
>>>>>    document.getElementById("out_portsel").add(optout);
>>>>>    for (listoutput = Lportout.next(); listoutput &&
>>>>>    !listoutput.done; li 
>>>> stoutput = Lportout.next()) {
>>>>>      var deviceOut = listoutput.value.name;
>>>>>      optout.text = deviceOut;
>>>>>      document.getElementById("out_portsel").add(optout);
>>>>>    }
>>>>
>>>> What is the reason for this code not showing any element within loop
>>>> just the extra added option? It seem to me it should add to the
>>>> elements created in loop?
>>>>
>>>>   var optout = document.createElement("option");
>>>>    for (listoutput = Lportout.next(); listoutput && !listoutput.done;
>>>>    listoutput = Lportout.next()) {
>>>>      var deviceOut = listoutput.value.name;
>>>>      optout.text = deviceOut;
>>>>      document.getElementById("out_portsel").add(optout);
>>>>    }
>>>>    test= document.getElementById("out_portsel");
>>>>    optout.text = "SF2 SYNTH WEB";
>>>>    test.add(optout);
>>>
>>> You will need a NEW optout each time, meThinks():
>>>
>>> [ES2015]
>>> for (...) {
>>>      const optout = document.createElement("OPTION");
>>>      ...
>>>      document.getElementById("out_portsel").appendChild(optout);
>>> };
>>>
>>>
>>>
>>> -- 
>>> Evertjan.
>>> The Netherlands.
>>> (Please change the x'es to dots in my emailaddress)
>> 
>> Maybe i missunderstand you, but the loop reading ports/devices into the
>> option list work just fine no matter how many ports devices i have. 
>> 
>> The problem arise when i want to add a pseudo port of my own to the
>> list before, after or at index an index. 
>> 
>> Before it will be overwritten in loop, after it will be the only option
>> element. JT
>> 
> 
> If the node argument to appendChild *already* is in the document, it 
> will simply be moved to the new position.

That is why one should declare a NEW <OPTION> element each time,
or configure one's [= Jonas'es] Q better.

-- 
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

Adding extra element "to option list" using next loop? Jonas Thörnvall <jonas.thornvall@gmail.com> - 2018-11-24 00:40 -0800
  Re: Adding extra element "to option list" using next loop? Jonas Thörnvall <jonas.thornvall@gmail.com> - 2018-11-24 05:35 -0800
  Re: Adding extra element "to option list" using next loop? Jonas Thörnvall <jonas.thornvall@gmail.com> - 2018-11-25 19:57 -0800
    Re: Adding extra element "to option list" using next loop? "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2018-11-26 13:05 +0100
      Re: Adding extra element "to option list" using next loop? Jonas Thörnvall <jonas.thornvall@gmail.com> - 2018-11-26 22:45 -0800
        Re: Adding extra element "to option list" using next loop? Jake Jarvis <pig_in_shoes@yahoo.com> - 2018-11-27 10:30 +0100
          Re: Adding extra element "to option list" using next loop? "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2018-11-27 12:08 +0100
            Re: Adding extra element "to option list" using next loop? Jonas Thörnvall <jonas.thornvall@gmail.com> - 2018-11-27 12:43 -0800
              Re: Adding extra element "to option list" using next loop? "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2018-11-27 23:39 +0100
                Re: Adding extra element "to option list" using next loop? Jonas Thörnvall <jonas.thornvall@gmail.com> - 2018-11-28 20:25 -0800

csiph-web