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 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Sep 2011
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Internet Explorer length is null or not an object error in IE8

    Hi,
    I have added an validation script for Pizza menu. Validation working fine in all browsers except IE.
    When I working in IE8 it throws an error "length is null or not an object error in IE8".
    Please help me. See Java script code below:
    <script>
    function UnCheckRadios(radioButtonGroupName)
    {

    var formName = "frmOrder";
    var form = document.forms[formName];
    alert(form);
    var noOfRadioButtons=form[radioButtonGroupName].length;
    for(var x=0;x<noOfRadioButtons;x++)
    {
    chk=form[radioButtonGroupName]
    .checked=false;

    }
    }
    </script>

    PHP code:
    <input type="radio" id="<?=$subitem['subgroup_id'];?>_comboleft" name="<?=$subitem['subgroup_id'];?>_comboleft" value="<?=$subitem['id'];?>:Left Side" onclick="UnCheckRadios('<?=$subitem["subgroup_id"];?>_combowhole');">

  • #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
    In classical JavaScript reference model, a group of radio buttons has no length if there is only a single button. Beside any javascript explanation (the ambiguity between single elements and a group of elements with the same name), it looks obvious that radio buttons should be used only in a group, not isolated.

    Anyway, there are several ways to solve that. The simplest, probably, is to use the DOM 1 reference document.getElementsByName(). That will return a collection in any situation
    Code:
    function UnCheckRadios(radioButtonGroupName){
    var radios=document.getElementsByName(radioButtonGroupName), r, i=0;
    while(r=radios[i++]){
    r.checked=false;
    }
    }
    And: important - your code shows that you are giving both an id and a name to your elements. But name and id are different tokens, as, unlike the name, the id must be unique on document. Remove the id.
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*


  •  

    Posting Permissions

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