www.webdeveloper.com
Results 1 to 4 of 4

Thread: Variable Undefined in Firefox but working in IE

  1. #1
    Join Date
    Nov 2008
    Posts
    12

    Variable Undefined in Firefox but working in IE

    Hi,

    I am trying to fix up some code and have run into a problem. For some reason the line of code
    Code:
    var sizeQ = gid("q" + aq).length;
    is not assigning a value when the page is loaded in firefox but in IE it works perfectly.

    Please see the complete function below:
    Code:
    function testAnswers(aqNow,review,toClose){
    	//alert("inside test answers");
       var listQa = gid("listQuestions").value;
    
       var arrListQa = listQa.split(",");
       var arrToClose = toClose.split(",");
       //alert("question answered ->"+arrListQa.length);
       //alert("array is " + listQa);
    
       if(listQa!="" && review != "true"){
    	   //alert("inside first part");
    		   for (var i=0; i < arrListQa.length; i++){
    				 var aq = arrListQa[i];
    				 alert("aq is " + aq);
    				// gid("debug").innerHTML += aq+"<br>";
    				 //if(aq != aqNow){
    
    					var sizeQ = gid("q" + aq).length;
    					
    					alert("sizeQ is " + sizeQ);
    					 
    					 
    				/*	 
    					 var test = gid("q"+aq);
    					 alert("test is" + test);
    					 
    					 var test2 = document.getElementById(test.length);
    					 alert("VALUE: " + test2);
    					 
    					 var test3= document.getElementById(aq);
    					 alert("test3 is" + test3);
    					 
    					 alert("does this work: " + gid("q" + aq).length);
    					*/ 
    					 
    					 //gid("debug").innerHTML += sizeQ+"<br>";
    					 //alert("question answered ->"+sizeQ);
    					 var contQ = 0;
    				     var contQA = 0;
    						for (var j=0; j < sizeQ; j++)
    							{
    								typField = gid("q"+aq)[j].type;
    								
    								if (((typField == "radio" || typField == "checkbox")&& gid("q"+aq)[j].checked) || (typField == "text" && gid("q"+aq)[j].value != "")){	
    									contQA ++;
    								}
    								name = gid("q"+aq)[j].name;
    								
    								if (name!=nameNow){
    									nameNow = name; 
    									contQ +=1;
    									
    									}
    								
    								//if(typField == "checkbox"){gid("debug").innerHTML +="[checkbox]"+gid("q"+aq)[j].checked + "<br>";}
    								
    								//gid("debug").innerHTML += name+"["+contQA + " - " + contQ+"]<br>";
    								
    							}
    							
    							
    						if((contQA >= contQ) && (contQA != 0)){
    							alert("inside control if statement");
    							controlSeeMore(aq);							
    						};
    				 //}
    		   }
       }
    If anyone could help me out with this i would be very greatful.

    Thanks in advace,

    almac007
    Last edited by Kor; 01-15-2010 at 04:22 AM. Reason: wrap the code [code][/code]

  2. #2
    Join Date
    Apr 2003
    Location
    Netherlands
    Posts
    21,654
    What is gid?
    At least 98% of internet users' DNA is identical to that of chimpanzees

  3. #3
    Join Date
    Nov 2008
    Posts
    12
    Hi Fang,

    here is the code for the gid function:

    var vrs=navigator.appVersion;
    var IE=((vrs.indexOf("IE") > -1) || (vrs.indexOf("Mac") > -1));

    function gid(v){
    if ((vrs.indexOf("IE") > -1) || (vrs.indexOf("Mac") > -1) )return document.all[v];
    else return document.getElementById(v);
    }

  4. #4
    Join Date
    Dec 2003
    Location
    Bucharest, ROMANIA
    Posts
    15,428
    You can safely use:
    Code:
    function gid(v){
    return document.getElementById(v);
    }
    On the other hand make sure your elements have an id (not only a name, but an id)

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

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



Recent Articles