Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!usenet.blueworldhosting.com!feeder01.blueworldhosting.com!feeder.erje.net!eu.feeder.erje.net!weretis.net!feeder1.news.weretis.net!news.solani.org!.POSTED!not-for-mail From: Thomas 'PointedEars' Lahn Newsgroups: comp.lang.javascript Subject: Re: Dynamically assign image map values? Date: Thu, 30 Oct 2014 19:46:04 +0100 Organization: PointedEars Software (PES) Lines: 68 Message-ID: <28301755.4F9RsBvy3v@PointedEars.de> References: Reply-To: Thomas 'PointedEars' Lahn Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8Bit X-Trace: solani.org 1414694766 31063 eJwFwQkBwDAIA0BL40kocqAF/xJ2B6PwhhN0LLa6Pp0WD9jTu0EtzTc2c+QRJXk2NcGs3pQfJnwRPA== (30 Oct 2014 18:46:06 GMT) X-Complaints-To: abuse@news.solani.org NNTP-Posting-Date: Thu, 30 Oct 2014 18:46:06 +0000 (UTC) User-Agent: KNode/4.14.1 X-User-ID: eJwFwQkBwDAIA0BLLYRA5TAe/xJ2Z8rLctAIW1u2ThpPAaHCmxYY/8LRA2VWhvDYkelU1RYJt00U+8m+/QE6ZxUI Cancel-Lock: sha1:qum/Pxc1wWqw/LVd5wFhV7572fw= X-NNTP-Posting-Host: eJwNyscBwDAIBLCVaEcZJwaz/wiO3oI6e4c53LDYO4XSuRhuka4lCW7Qd5SlWC1TMv5N6n42HhMnEBo= Xref: csiph.com comp.lang.javascript:26048 Jukka K. Korpela wrote: > 2014-10-30 19:35, Tuxedo wrote: >> x1 = 100; y1 = 100; x2 = 300; y2 =300; >> >> area.setAttribute("coords","+x1+","+y1+","+x2+","+y2+"); >> >> But this is wrong. > > Yes, because only the second argument matters here, the rest are > discarded. You need this: > > area.setAttribute("coords", x1 + "," + y1 + "," + x2 + "," + y2); This and all other setAttribute() calls should be replaced with the corresponding form of area.coords = x1 + "," + y1 + "," + x2 + "," + y2; (Likewise, getAttribute() calls should be replaced by property-read access unless the original markup attribute value is wanted.) [1] Another possibility here is area.coords = [x1, y1, x2, y2]; or (probably safer) area.coords = [x1, y1, x2, y2].toString(); or area.coords = [x1, y1, x2, y2].join(); or (explicit) area.coords = [x1, y1, x2, y2].join(","); The first form should work (untested in recent environments, but supported by previous experience) because the type of the “coords” property should be String, as it is an implementation of an interface attribute whose type is DOMString; so a built-in setter of that property should convert the value RHS to String. Then the following applies: The string representation of an Array instance is the comma-separated list of the string representation of its elements as returned by Array.prototype.toString(). The string representation of String values is their value; the string representation of Number values is the one that most closely represents the nearest IEEE-754 “double precision” floating-point value, in the simplest case the concatenated decimal digits. As for the second one, the toString() method inherited by Array instances returns the same as the inherited join() method when called without argument. Array.prototype.join() without argument (with argument “undefined”) defaults to a comma (“,”) as separator. [2] This is “probably safer” than the former approach because it does not rely on a type- converting setter LHS. _________ [1] (sic!) [2] pp. -- PointedEars FAQ: | SVN: Twitter: @PointedEars2 | ES Matrix: Please do not Cc: me. / Bitte keine Kopien per E-Mail.