View Full Version : length is null or not an object error in IE8

09-27-2011, 08:21 AM
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:
function UnCheckRadios(radioButtonGroupName)

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


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');">

09-27-2011, 04:55 PM
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

function UnCheckRadios(radioButtonGroupName){
var radios=document.getElementsByName(radioButtonGroupName), r, i=0;

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.

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum