View Full Version : Selecting all items in a document

10-19-2003, 05:53 AM
I am trying to select all the elements on a form and throw an alert box if any of the selected elements are disabled. All of the form elements are radio buttons; however, there are about 10 groups of them. When some are clicked, I have conditional statements disabling some of the others. Appreciate the help!

10-19-2003, 09:51 AM
seems a little bit confusing for me... If you have groups, then you have the same name in a gruop, so you will never have all the radio checked... Can you detail please?

10-20-2003, 12:06 AM
Sure, say for example, you were choosing a car. You could decide between Chevy, Honda, and Jeep, and you can accesorize it with colors: Red, Blue, Green--or type: sedan, sportscar, or SUV. Chevys cannot be green, Hondas cannot be blue or SUV, and Jeep cannot be Sedan. There is appropiate coding for all to disable the elements that cannot occur between different selections. If the person chose Chevy and blue, and changed their mind to Honda, the blue remains checked even though it's been disabled. I need to throw an alert for all instances of this on the page. My form is a little more complicated than this, but it's the general idea. I'll include it if you want a laugh.


PS..I was thinking a blanket statement such as
if (document.thiselements.disabled==true && document.thiselement.checked==true){
alert ("There is an error in your selection");}

10-20-2003, 09:47 AM
Ok, I got it... I suggest you better simply make a code to disable the check on following elements if, on the previous group, the check is changed, rather then to alert the change. Smply clear the check buttons... You know how to do it? Of course, it can be done in your way, using a verifying condition with return true/false within an if contion... Do you want an example?

10-20-2003, 10:04 AM
so what you want is when a particular radio is disabled, and it's checked by the user, it should be unchecked?

if so, then when you disabled a radio, you should uncheck it also. That way, no instance of checked and disabled radio will exist.

radioReference.disabled = true;
radioReference.checked = false;

10-20-2003, 11:19 AM
Yes, but if there is a goup of radio buttons (ie have the same name) the general (the group) or individual false/true values are complementary, so that the group value is indefined, nor true nor false. So beware...

Now here's a simple example of what you might need:

function verify(){
if((document.forms[0].two[0].checked) || (document.forms[0].two[1].checked))
alert('See if the check is correct on the group TWO!');
<input name="one" type="radio" onclick="verify()">
<input name="one" type="radio" onclick="verify()">
<input name="two" type="radio">
<input name="two" type="radio">

If you have too many radio buttons in a group (or for estetical reasons...) you may use an increment for the elements positions, something like:

for (i=0, i++,i<document.forms[0].elements_name.lenght) ...

(or for (i=0, i++,i<document.forms[0].elements[name].lenght) ... I don't remember now the precise syntax)


10-20-2003, 11:34 AM
... and to try to answer your theoretical question...

As far as I know, there is no way (at least in case of radio buttons group) to refere the the whole group of elements, with common name, by their name, otherwise than to refere each element (additionaly or incrementaly).

Maybe someone else knows much...

10-21-2003, 10:20 AM
Wow, thx...you guys are great help!

10-21-2003, 10:35 AM
Wow, thx...you guys are great help!