Path: csiph.com!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Arno Welzel Newsgroups: comp.lang.javascript Subject: Re: InnerHTML quirks Date: Thu, 27 Jun 2019 11:00:40 +0200 Lines: 59 Message-ID: References: <6dcae054-0a58-4000-9bb0-0be37a937500@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Trace: individual.net V+uJcuqa11B83oEN/iqN1A8Cg4iXQ494Exczq0chogKIPV5cIQ Cancel-Lock: sha1:mkmjBsUTuTmJWMN1Y3MVQN/GzLw= In-Reply-To: Content-Language: en-US Xref: csiph.com comp.lang.javascript:36943 On 27.06.19 10:43, Jonas Thörnvall wrote: > Den torsdag 27 juni 2019 kl. 10:18:30 UTC+2 skrev Arno Welzel: >> On 27.06.19 07:51, Jonas Thörnvall wrote: >>> Given i have an option list generated dynamically and then inserted to my main HTML file with using div. >>> >>>
>>> >>> And inserted using javascript. >>> function bankOptionList(){ >>> bankOptNames=""; >>> bankSelect ="BANK: \n"; >>> bankOptionString=bankSelect+bankOptNames+bankOptEnd; >>> //alert(bankOptionString); >>> document.getElementById("bankOptList").innerHTML=bankOptionString; >>> } >>> >>> >>> How can i set selected index? >> >> By setting the "selected" attribute for the option, which should be >> selected intially. >> >> Also see: >> [...] > The whole point with my post is that it does not work for innerHTML Arno. It DOES: For a selected element - and ONLY for this - use: if(r == my_selected_index) { selattr = " selected=\""selected\\""; } else { selattr = "" } bankOptNames+="\n"; > So the question is howto set the selected index for an option list "within a segment of innerHTML". See above. And you should really try to *LEARN* how to use JavaScript and HTML and not just do copy & paste. -- Arno Welzel https://arnowelzel.de