A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: IE7 not setting an array

Threaded View

  1. #1
    Senior Member
    Join Date
    Nov 2004
    Location
    Toronto, Canada
    Posts
    194

    IE7 not setting an array

    This is completely inexplicable.

    The function below gets all forms on the page, gets all form fields in each form and sets each field's onblur and onfocus event handlers to change the css class name. IE7 seems to think my form doesnt have any input fields, and when I alert the length of the fields[0] array I don't get undefined, or null or "", I get [object]! same when I alert fields[0].length.toString() and forms[0].getElementsByTagName('input').length and forms[i].getElementsByTagName('input').length.toString();

    It doesn't throw any exceptions when i run it and it works fine in Firefox 2, FireBug even thinks the script is fine (which it is )

    I even tried creating a separate for loop outside the rest of the functionality just for the array of input tags and still nothing!!

    here is the page so you can see for yourself http://www.pedigreepalace.com/account/listdog.cfm

    THIS MAKES NO SENSE!!

    Code:
    //sets the classes for all form objects when they blur and focus
    function setBlurAndFocus()
    {
    	var forms = document.getElementsByTagName('form');
    	
    	for(var i = 0; i < forms.length; i++)
    	{
    		var fields = new Array();
    		var totWidth = 0;
    		fields[0] = forms[i].getElementsByTagName('input');
    		fields[1] = forms[i].getElementsByTagName('select');
    		fields[2] = forms[i].getElementsByTagName('textarea');
    				
    		for(var k = 0; k < fields.length; k++)
    		{
    			//alert(forms[i].getElementsByTagName('input').length + ', ' + j);
    			for(var j = 0; j < fields[k].length; j++)
    			{
    				//alert(k + ', ' + j);
    				if(fields[k][j].tagName == "INPUT")
    				{
    					
    					if(fields[k][j].type != "submit" && fields[k][j].type != "button")
    					{
    						if(fields[k][j].type != "file")
    						{
    							totWidth += fields[k][j].offsetWidth;
    						}
    						
    						fields[k][j].className = 'blur';
    						
    						fields[k][j].onblur = function()
    						{
    							this.className = 'blur';
    						}
    						
    						fields[k][j].onfocus = function()
    						{
    							this.className = 'focus';
    						}
    					}
    				}
    				else
    				{
    					fields[k][j].className = 'blur';
    					
    					fields[k][j].onblur = function()
    					{
    						this.className = 'blur';
    					}
    						
    					fields[k][j].onfocus = function()
    					{
    						this.className = 'focus';
    					}
    				}
    			}
    		}
    		
    		/*var fieldSets = forms[i].getElementsByTagName('fieldset');
    		
    		for(var x = 0; x < fieldSets.length; x++)
    		{
    			if(fieldSets[x].style.width == undefined || fieldSets[x].style.width == "")
    			{
    				fieldSets[x].style.width = Math.round(totWidth / fields[0].length) + "px";		
    			}
    		}*/
    	}
    }
    Last edited by Ogre11; 12-14-2006 at 05:31 PM.

Posting Permissions

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




Click Here to Expand Forum to Full Width

HTML5 Development Center