Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 9 of 9
  1. #1
    New Coder
    Join Date
    Oct 2003
    Posts
    24
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Selecting all items in a document

    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!

  • #2
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    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?
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • #3
    New Coder
    Join Date
    Oct 2003
    Posts
    24
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.

    Thanks

    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");}
    Attached Files Attached Files
    Last edited by xupaosso; 10-19-2003 at 11:09 PM.

  • #4
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    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?
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • #5
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,048
    Thanks
    0
    Thanked 251 Times in 247 Posts
    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;

  • #6
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    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:

    PHP Code:
    <html>
    <
    head>
    <
    script>
    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!');
    }
    }
    </script>
    </head>
    <body>
    <form>
    ONE<br>
    <input name="one" type="radio" onclick="verify()">
    <input name="one" type="radio" onclick="verify()">
      <br>
    TWO<br>
    <input name="two" type="radio">
    <input name="two" type="radio">
    </form>
    </body>
    </html> 

    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)

    if(document.forms[0].two[i].checked)......
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • #7
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    ... 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...
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • #8
    New Coder
    Join Date
    Oct 2003
    Posts
    24
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Wow, thx...you guys are great help!
    Help! I've reached the end of my code!

  • #9
    New Coder
    Join Date
    Oct 2003
    Posts
    24
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Wow, thx...you guys are great help!
    Help! I've reached the end of my code!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •