473,326 Members | 2,108 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

var e = form.elements;

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
Jul 23 '05 #1
4 1708
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

Jul 23 '05 #2

"RobB" <fe******@hotmail.com> wrote in message news:11*********************@c13g2000cwb.googlegro ups.com...
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

Cool thanks, I will push them I think. Great. Thanks for your help.
Jul 23 '05 #3
"WindAndWaves" <ac****@ngaru.com> wrote in message
news:f%*********************@news.xtra.co.nz...
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

Cool thanks, I will push them I think. Great. Thanks for your help.


If you know what you want to do with the form elements right away, then
why pass through the elements collection once, then pass through the
list of matching elements a second time?

var f;
if ((f = document.forms) &&
(f = f['yourForm']) &&
(f = f.elements))
{
var ii = f.length;
while (ii-- > 0)
// or
// for (var ii = 0; i < f.length; ++ii)
// if direction matters
{
if (f[ii].type == 'checkbox' &&
/^r/i.test(f[ii].name))
{
// do something with f[ii]
}
}
}

--
Grant Wagner <gw*****@agricoreunited.com>
comp.lang.javascript FAQ - http://jibbering.com/faq
Jul 23 '05 #4

"Grant Wagner" <gw*****@agricoreunited.com> wrote in message news:qa***************@news2.mts.net...
"WindAndWaves" <ac****@ngaru.com> wrote in message
news:f%*********************@news.xtra.co.nz...
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

Cool thanks, I will push them I think. Great. Thanks for your help.


If you know what you want to do with the form elements right away, then
why pass through the elements collection once, then pass through the
list of matching elements a second time?

var f;
if ((f = document.forms) &&
(f = f['yourForm']) &&
(f = f.elements))
{
var ii = f.length;
while (ii-- > 0)
// or
// for (var ii = 0; i < f.length; ++ii)
// if direction matters
{
if (f[ii].type == 'checkbox' &&
/^r/i.test(f[ii].name))
{
// do something with f[ii]
}
}
}

--
Grant Wagner <gw*****@agricoreunited.com>
comp.lang.javascript FAQ - http://jibbering.com/faq


Thank you Grant.
Jul 23 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Edward | last post by:
The following html / javascript code produces a simple form with check boxes. There is also a checkbox that 'checks all' form checkboxes hotmail style: <html> <head> <title></title> </head>...
2
by: Edward | last post by:
The below code builds 2 tables 4 rows by 4 cols. All cells have checkboxes. When checked, the checkboxes in the first column automatically check the remainder of the check boxes in the same row. ...
1
by: Howard Jess | last post by:
Apparently, form elements of type <input type="image" src="...> are not included in the form's elements collection. I don't understand why not; according to DOM2, all form control elements...
6
by: francisco lopez | last post by:
ok , first of all sorry if my english is not so good, I do my best. here is my problem: I don´t know much javascript so I wrote a very simple one to validate a form I have on my webpage. ...
4
by: pizzy | last post by:
INTRO: I tried to clean it up for easy reading. I hope I didn't make any mistakes. PROBLEM: WOW, this is some crazy sh!t. I can't get my checkbox (see "TAGSELECTED") to print my textboxes (see...
6
by: Chris Styles | last post by:
Dear All, I've been using some code to verify form data quite happily, but i've recently changed the way my form is structured, and I can't get it to work now. Originally : The form is...
2
by: justplain.kzn | last post by:
Hi, I have a table with dynamic html that contains drop down select lists and readonly text boxes. Dynamic calculations are done on change of a value in one of the drop down select lists. ...
2
by: mars123 | last post by:
hi, I am facing a js error in my code, below is the prob. statement I have a radio2 javascript function as below, it works like this.. When a parent radio button is selected only one of its...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.