SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Hybrid View

  1. #1
    SitePoint Enthusiast
    Join Date
    Mar 2011
    Posts
    28
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    colspan property has no effect

    i have the following code which creates tr and td elements then adds them to a table. combArray is a global array and there are no problems inserting all the values. the only problem is assigning a colspan = 7 has no effect; everything is still squished into 1 row. The entire function runs and is not crashing. i even try and assign colspan twice, once on line 11 and again after the row has been appended at the end of the function on line 40. why isnt colspan working?! thanks in advance, Geoff

    Code:
    <script type="text/javascript">	
    function fillVariables( idDigit ) {
    	var tbody = document.getElementById("zrow" + idDigit + "tbody");
    	var newNodeText = "";
    	var varCount = 1;
    	var fixedCount = 1;
    
    	for (var x = 0; x < combArray.length; x++ ) {
    		var newNodeTr = document.createElement("tr");
    		var newNodeTd = document.createElement("td");
    		newNodeTd.colspan = 7;
    		newNodeTd.id = "td1" + idDigit;
    		//newNodeTd.colspan = 2;
    		if (combArray[x][4] == "yes") {
    			newNodeText = "Variable ingredient " + varCount + ": " + combArray[x][0] + " (" + combArray[x][1] + ") ";
    			if (combArray[x][2] != "") { // combArray ingredient uses SA
    				var SAObj = fractionToDecimal (combArray[x][2]);
    				newNodeText = newNodeText + "<input id=\"varval_" + idDigit + "_" + x + "\" type=\"text\" size=\"3\" value=\"" + formatFTD( SAObj ) + "\" /> ";
    				newNodeText = newNodeText + "<span id=\"varsa_" + idDigit + "_" + x + "\">" + SAObj.text + "</span>";
    			} else {
    				newNodeText = newNodeText + "<input id=\"varval_" + idDigit + "_" + x + "\" type=\"text\" size=\"3\" value=\"" + parseFloat( combArray[x][3] ) + "\" /> ";
    				newNodeText = newNodeText + createUnitSelect( combArray[x][3], "varss_" + idDigit + "_" + x );			
    			}
    			varCount += 1;
    		} else {
    			newNodeText = "Fixed ingredient " + fixedCount + ": " + combArray[x][0] + " (" + combArray[x][1] + ") ";
    			if (combArray[x][2] != "") { // combArray ingredient uses SA
    				newNodeText = newNodeText + combArray[x][2];
    			} else { //combArray ingredient uses SS/
    				newNodeText = newNodeText + combArray[x][3];
    			}
    
    			fixedCount += 1;
    		}
    
    		newNodeTd.innerHTML = newNodeText;
    		newNodeTr.appendChild(newNodeTd);
    		tbody.appendChild(newNodeTr);
    
    		document.getElementById("td1" + idDigit).colspan = 7;
    		alert("check14. this shows up meaning function does not crash.");
    	}
    }
    </script>

  2. #2
    SitePoint Addict skunkbad's Avatar
    Join Date
    Apr 2008
    Location
    Temecula, CA
    Posts
    278
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Are you applying colspan to the tr or the td? I had an issue with colspan yesterday, and it was because I was applying it to the tr, and not the td. Are you using firebug, and can you see how the html is being rendered?

  3. #3
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,729
    Mentioned
    104 Post(s)
    Tagged
    4 Thread(s)
    The property you're looking for is pronounced colSpan, not colspan.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript


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
  •