Prev: ISO 8601 date format
Next: Quicktime and innerHTML
From: laredotornado on 23 Apr 2010 16:43 Hi, If I am given an element name (e.g. the "name" attribute of a DOM object), how can I test if that element is a radio button? Thanks, - Dave
From: Gregor Kofler on 23 Apr 2010 17:06 Am 2010-04-23 22:43, laredotornado meinte: > Hi, > > If I am given an element name (e.g. the "name" attribute of a DOM > object), how can I test if that element is a radio button? With its type property. Gregor -- http://www.gregorkofler.com
From: laredotornado on 23 Apr 2010 17:48 On Apr 23, 4:06 pm, Gregor Kofler <use...(a)gregorkofler.com> wrote: > Am 2010-04-23 22:43, laredotornado meinte: > > > Hi, > > > If I am given an element name (e.g. the "name" attribute of a DOM > > object), how can I test if that element is a radio button? > > With its type property. > > Gregor > > --http://www.gregorkofler.com I tried that, but it is not producing anything. On my page, I have a single form, and this code console.log("elt name:" + eltName + " type:" + document.forms[0].elements[eltName].type); produces: elt name:functionSpace type:undefined Here is the HTML ... <div class="field-wrapper"> <label for="function-space-yes" class="lbl-function"> *Function space and /or meeting space needed? </label><br /> <input id="function-space-yes" name="functionSpace" class="empty lbl-function" type="radio" value="yes"/> Yes <input id="function-space-no" name="functionSpace" class="empty lbl-function" type="radio" value="no"/> No </div> - Dave Any other thoughts? - Dave
From: Thomas 'PointedEars' Lahn on 23 Apr 2010 18:13 laredotornado wrote: > Gregor Kofler wrote: >> laredotornado meinte: >> > If I am given an element name (e.g. the "name" attribute of a DOM >> > object), how can I test if that element is a radio button? >> >> With its type property. > > I tried that, but it is not producing anything. On my page, I have a > single form, and this code > > console.log("elt name:" + eltName + " type:" + > document.forms[0].elements[eltName].type); > > produces: > > elt name:functionSpace type:undefined > > Here is the HTML ... That is not interoperable HTML, the slashes do not belong there in HTML: > <div class="field-wrapper"> > <label for="function-space-yes" class="lbl-function"> > *Function space and /or meeting space needed? > </label><br /> ^^ > <input id="function-space-yes" name="functionSpace" class="empty > lbl-function" type="radio" value="yes"/> ^ > Yes > <input id="function-space-no" name="functionSpace" class="empty > lbl-function" type="radio" value="no"/> ^ (see also <http://validator.w3.org/>) -' When two controls in the same form have the same name, as it must be the case for each item of a radio button group, they are referred to by items of a NodeList implementation. That object does not have a `type' property, but the objects its items refer to have. console.log("elt name:" + eltName + " type:" + document.forms[0].elements[eltName][0].type); This is a very old and very well-known issue. One must wonder if you have ever RTFM, or have read the FAQ. <http://jibbering.com/faq/#formControlAccess> PointedEars -- realism: HTML 4.01 Strict evangelism: XHTML 1.0 Strict madness: XHTML 1.1 as application/xhtml+xml -- Bjoern Hoehrmann
|
Pages: 1 Prev: ISO 8601 date format Next: Quicktime and innerHTML |