By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,851 Members | 1,118 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,851 IT Pros & Developers. It's quick & easy.

Check the value of all combo boxes on a page

P: n/a
I have a page with many, dynamically generated combo boxes and I want
to check all of them, before I add a unique value to specific combo.
What would be the best way to work through the document and without
needing to know the name of each combo box, check its value?

Thanks,

Stephen
Jul 23 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Stephen Miller wrote:
I have a page with many, dynamically generated combo boxes and I want
to check all of them, before I add a unique value to specific combo.
What would be the best way to work through the document and without
needing to know the name of each combo box, check its value?


There is no such thing like combo boxes in HTML. You probably mean
check boxes:

if (document.getElementsByTagName)
{
var o = document.getElementsByTagName('input');
if (o)
{
for (var i = o.length; i--; 0)
{
if (o.type = "checkbox")
{
o.checked = true;
}
}
}
}

What do users without support for client-side JS?
PointedEars
--
"Birth gives rise to old age and death."
-- Siddhartha Gautama, the Buddha
Jul 23 '05 #2

P: n/a
In article <cd**************************@posting.google.com >,
js******@hotmail.com enlightened us with...
I have a page with many, dynamically generated combo boxes
You mean select elements?
Combo boxes are VB and allow both a selection and text input.
and I want
to check all of them, before I add a unique value to specific combo.
What would be the best way to work through the document and without
needing to know the name of each combo box, check its value?


Please explain what you mean by "check its value".
Select elements have options. They also have a selectedIndex property to tell
which option has been chosen. The options have values.
Do you want to check what options (option values) are in each select, which
option has been chosen for a select...?

To iterate through a form, named "form1":

var L = document.forms["form1"].elements.length;
for (var i=0; i<L; i++)
{
/* 'e' will be a form element; do whatever with it */
var e = document.forms["form1"].elements[i];
}

'e' will have a type, name, and all other attributes associated with a form
element.
Example:
alert(e.name);
alert(e.type);

I'm assuming the elements are in a form. The above is more cross-browser than
using getElementsByTagName, but I think it's also slower. Using
getElementsByTagName, however, will allow you to get all the select elements
across ALL forms in a page if you have multiple forms, not just one. There's
pros and cons to each choice.
And don't forget - not everyone has javascript enabled or even available.

HTH
--
--
~kaeli~
A man needs a mistress... just to break the monogamy.
http://www.ipwebdesign.net/wildAtHeart
http://www.ipwebdesign.net/kaelisSpace

Jul 23 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.