SitePoint Sponsor

User Tag List

Results 1 to 5 of 5

Hybrid View

  1. #1
    SitePoint Guru
    Join Date
    Dec 2005
    Posts
    982
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    IE Crashing, but FF Loves It

    I am working on an unobtrusive table manipulation script that will delete a row and recreate it with some additional form elements. Firefox works 100%. I thought I took extra care to keep IE happy, but when I first attempted to run the script in IE6, it crashes pretty hard. The crash I get is:
    Internet Explorer cannot open the Internet site <<my site>>.

    Operation aborted
    There are no details that I can see that really help me narrow down the reason, so I've been snipping code until I found the culprit. it appears that using appendChild IE is crashing immediately. Hopefully there is a simple cross browser fix to this? I thought appendChild was pretty straight forward, but I'm usually wrong when it comes to JS.

    Here is the trimmed down JS:
    Code JavaScript:
    function inv_load_attr() {
    	if(!document.productForm.p_a_count || document.productForm.p_a_count.value > 1) return false;
     
    	var attributesTable = document.getElementById('product-attributes');
     
    	//create hidden attributes
    	if (!window.ActiveXObject) {
    		//DOM compliant
    		var hidden_formcode = document.createElement('input');
    		    hidden_formcode.name = 'p_a_code';
    	} else {
    		//IE (for support of [document.elementForm.elementName])
    		var hidden_formcode = document.createElement('<input name="p_a_code" />');
    	}
    	    hidden_formcode.type = 'hidden';
    	    hidden_formcode.id = 'p_a_code';
    	    hidden_formcode.value = 'size_color';
    	    attributesTable.parentNode.appendChild(hidden_formcode);
    };

    To get an idea of the HTML that this is being used for, here's everything inside of my <body>:

    Code HTML:
    <form method="post" action="/submit.php" id="productForm" name="productForm">
    	<input type="hidden" name="p_a_count" value="1" />
     
    	<table cellspacing="0" id="product-attributes">
    	  <tr>
    		<td>
    			<label for="p_a_value" class="attrLabel required"">Size / Color:</label>
     
    		</td>
    		<td>
    			<input type="hidden" name="p_a_code" value="size_color" />
    			<select name="p_a_value" id="p_a_value">
    				<option value="">&lt; Select One &gt;</option>
    				<option value="S_WHITE">Small / White</option>
    				<option value="M_WHITE">Medium / White</option>
    				<option value="L_WHITE">Large / White</option>
    			</select><br />
    		</td>
    	  </tr>
    	<script type="text/javascript">
    		inv_load_attr();
    	</script>
    	</table>
     
    	<input type="image" src="/images/submit.gif" alt="Add to Cart" value="Add to Cart" id="cart-submit" class="inputSubmit" />
    </form>

    What am I doing wrong? I have seen .appendChild() being used in other scripts that seem to work in IE. Any thoughts?

    Thanks

    Brandon
    MySQL v5.1.58
    PHP v5.3.6

  2. #2
    SitePoint Wizard Pepejeria's Avatar
    Join Date
    Jan 2005
    Location
    Too far up north
    Posts
    1,566
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Do you have any URL where this can be seen?

  3. #3
    SitePoint Guru
    Join Date
    Dec 2005
    Posts
    982
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Unfortunately I do not. If it's a problem I might be able to set up a test page tonight when I get home.
    MySQL v5.1.58
    PHP v5.3.6

  4. #4
    SitePoint Guru
    Join Date
    Dec 2005
    Posts
    982
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The fix was easier than I expected. I was trying to use appendChild before the DOM had finished loading and IE exits fatally if you try that. I simply used the old window.onload quickfix and everything seems to be operational again....
    MySQL v5.1.58
    PHP v5.3.6

  5. #5
    SitePoint Zealot the DtTvB's Avatar
    Join Date
    Jul 2006
    Location
    Thailand
    Posts
    162
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If this problem occurs, you have to do it when a document is loaded instead.

    You cannot create elements and place it when a document is loading in IE.

    And guess what, IE is caching that error page.


Bookmarks

Posting Permissions

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