WindAndWaves wrote:
Hi Gurus
I have the following statement in my code:
var e = form.elements;
Is it possible to put any conditions on this statement. What I
actually want to say is:
var e = form.elements BUT ONLY FOR CHECKBOXES THAT START WITH R.
IN that way <INPUT TYPE="checkbox" NAME="r23"> would be part of e,
but <INPUT TYPE="submit">, etc... would not be included
TIA
- Nicolaas
var e = form.elements
....simply creates a reference to the elements (array) object of,
presumably, a specific form. Object references, naturally, have no
conditions - they only indicate a memory address where data is stored.
What you need to do is 1) create a custom collection (a subset of
Form.elements[]) filtered for only the elements you desire, or 2)
filter at run-time to exclude unwanted controls.
1)
var els = document.forms[0].elements,
rBoxes = [], //collection
el,
i = 0;
while (el = els[i++])
if (el.type == 'checkbox'
&& /^r/i.test(el.name))
rBoxes.push(el);
2)
if (el.type == 'checkbox'
&&/^r/i.test(el.name))
{...do something with it