Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder4.news.weretis.net!newsreader4.netcologne.de!news.netcologne.de!newsfeed.arcor.de!newsspool1.arcor-online.net!news.arcor.de.POSTED!not-for-mail Content-Type: text/plain; charset="UTF-8" Message-ID: <3066356.jABcFccoKv@PointedEars.de> From: Thomas 'PointedEars' Lahn Reply-To: Thomas 'PointedEars' Lahn Organization: PointedEars Software (PES) Date: Sun, 08 Dec 2013 19:35:04 +0100 User-Agent: KNode/4.11.3 Content-Transfer-Encoding: 8Bit X-Face: %i>XG-yXR'\"2P/C_aO%~;2o~?g0pPKmbOw^=NT`tprDEf++D.m7"}HW6.#=U:?2GGctkL,f89@H46O$ASoW&?s}.k+&. MIME-Version: 1.0 Lines: 101 NNTP-Posting-Date: 08 Dec 2013 19:35:19 CET NNTP-Posting-Host: 919a9c7d.newsspool4.arcor-online.net X-Trace: DXC=FIBf[6Sm@NaUoRk[hk2Wal4IUK74Jc6;VgiM:44RZ\A8Wj X-Complaints-To: usenet-abuse@arcor.de Xref: csiph.com comp.lang.javascript:22259 Norman Peelman wrote: > On 12/08/2013 05:54 AM, Une Bévue wrote: >> on my page i have 10 buttons >> >> 5 for categories : >> "+", "-", "E", "S", "C" for Add, Remove, Edit, Save and Cancel >> >> the same buttons for items. >> >> I'm looking for clever idaes on how to manage those buttons. >> >> I know how to enbale/disable the buttons but i'm confused on how to have >> a clean and clever way to manage them versus the state of my JS. >> >> For example when I'm editing a category or an item, after having click >> on "E", i want to disable "+", "-" and "E", letting "S" and "C" enabled. >> >> Also my "S" button serves two purposes : saving an updated category/item >> or saving a modifies category/item >> >> Any help appreciated. > > So create functions that will enable and disable a passed array of > objects (control names) Control names are _not_ objects, they are primitive String values (DOMString per DOM interface). > such as: > > > function ButtonsDisable(buttons) It is customary in these languages that only names of functions that can be called as a constructor, and constant-like variables or (in some implementations) constants, start with a capital letter. (Constant-like variables and constants are then distinguished from functions that can be called as a constructor by the former's all-uppercase names.) > { > foreach (buttons as button) There is no “foreach” statement in any widely known ECMAScript implementation (there was “for each” in E4X, for which support unfortunately has been abandoned by Mozilla recently). A possibility would be a for…in statement, but a C-style “for” statement is more reliable here. > { > obj = document.getElementByID(button) There is no document.getElementByID() method provided by any DOM implementation. The property name is “getElementById”. Property names usually are case-sensitive in these languages and their applications. > obj.disabled = true > } > } > > function ButtonsEnable(buttons) > { > foreach (buttons as button) > { > obj = document.getElementByID(button) > obj.disabled = false > } > } > > So that up entering the code for *Edit*ing you would call the functions > like: > > ButtonsDisable(array("+","-","E")) There is no array() function in ECMAScript. There is an Array() constructor/factory that can be safely replaced with “[”…“]”, the Array Initialiser. > ButtonsEnable(array("S","C")) > > > Off the cuff code, may need tweaking It is rather *pseudo-code* that needs *translation* into a programming language. Apparently you are confusing ECMAScript with some other language, maybe with PHP (which you are equally challenged with, as your comp.lang.php record shows). > but that's the general idea. So > I'm guessing that if 'categories' or 'items' is empty you would: > > ButtonsDisable(array("-","E","S","C")) > ButtonsEnable(array("+")) OMG. Will you *please* stop posting suggestions until you have gotten a *minimum* clue? -- PointedEars Twitter: @PointedEars2 Please do not Cc: me. / Bitte keine Kopien per E-Mail.