Camilo Vergara Muñoz

Navigation

Skip navigation.

Search

Site navigation

Email conversation

FromCamilo Vergara Muñoz
ToMe
SubjectInserting Rows by Code
Date30 December 2005 16:48
Hello 

(First than all Thanks in advance for taking time to resolve this question)

I was looking for a solution in IE/MAC for inserting rows into a table, my
code works perfectly in IE, Mozilla, And all others but in IE/MAC something
is wrong, the code always inserts the row in the same table row index, Im
constructing the code into a C# component first, then I put it into the aspx
page, the commented code was a initial state of it, when I trying to get the
correct position to insert the new row, late I saw this new way to do that
into javascript bible, but this code makes the same thing in IE/MAC


"function InsertarFila(codigo,cantidad,descripcion,precio)"     +
"{"     +
"document.getElementById(\"" + this.DivCanasta + "\").style.display =
\"block\";"     +
"var Row,Cell;" +		
"var curtable	=	document.getElementById(\"" + this.TablaCanasta +
"\");"     +
//"var RowCounter	=	parseInt(curtable.rows.length);"
+
//"alert(RowCounter);"		+
//"Row			=	curtable.insertRow(curtable.rows.length);"
+
"Row			=	curtable.insertRow(-1);"     +

"Cell			=	Row.insertCell(0);"     +

"Cell.align		=	\"center\";"     +
"Cell.width		=	\"118px\";" +
"Cell.innerHTML	=	\"<font Class='" + this.ClaseItem + "'>\" +
descripcion + \"</font>\";"     +
"Cell			=	Row.insertCell(1);"     +
"Cell.align		=	\"center\";"     +
"Cell.width		=	\"56px\";" +
"Cell.innerHTML	=	\"<font Class='" + this.ClaseItem + "'>\" + cantidad
+ \"</font>\";"     +
"Cell			=	Row.insertCell(2);"     +
"Cell.align		=	\"right\";"     +
"Cell.width		=	\"66px\";" +
"Cell.innerHTML	=	\"<font Class='" + this.ClaseItem + "'>$\" +
FormatoN(precio,\".\") + \"</font>\";"     +
"Cell			=	Row.insertCell(3);"     +
"Cell.align		=	\"center\";"     +
"Cell.width		=	\"50px\";" +
"Cell.innerHTML	=	\"<IMG id=btn\" + codigo + \" style=\\\"CURSOR:
hand\\\" onclick=\\\"borrardecanasta('\"+ codigo +\"','\" + cantidad
+\"','\" + precio + \"')\\\" alt=\\\"Clic acá para borrar este Item\\\"
src=\\" + this.RutaImagenReprobar + ">\";"     +
"}"     +


Thanks Again, I'll be waiting for your answer.


Camilo Vergara Muñoz
FromMe
ToCamilo Vergara Muñoz
SubjectRe: Inserting Rows by Code
Date30 December 2005 17:12
Camilo,

> I was looking for a solution in IE/MAC for inserting rows into a table, my
> code works perfectly in IE, Mozilla, And all others but in IE/MAC something
> is wrong, the code always inserts the row in the same table row index

IE Mac does not understand DOM 2 HTML tables correctly, so if you need IE
mac support, you should avoid using 'cells', 'rows', 'insertRow', and
'insertCell'. Just stick to the basic appendChild, insertBefore, and
childNodes (remember that rows are children of the tbody, not the table -
make sure you have a tbody element).

This page should give you a better idea of why:
http://www.quirksmode.org/dom/w3c_html.html


Mark 'Tarquin' Wilton-Jones - author of http://www.howtocreate.co.uk/
FromCamilo Vergara Muñoz
ToMe
SubjectRe: Inserting Rows by Code
Date30 December 2005 19:12
Mark,

Thanks for your short time answer, for this case will be possible to
implement a innerHtml method with the html code of the rows, like your
sample? Because I never work with appendChild method.

Thanks In Advance.


Camilo Vergara Muñoz
FromMe
ToCamilo Vergara Muñoz
SubjectRe: Inserting Rows by Code
Date30 December 2005 12:20
Camilo,

> for this case will be possible to
> implement a innerHtml method with the html code of the rows, like your
> sample? Because I never work with appendChild method.

Sure, you can use innerHTML, but appendChild is very easy to use:
http://www.howtocreate.co.uk/tutorials/javascript/dombasics
FromCamilo Vergara Muñoz
ToMe
SubjectRe: Inserting Rows by Code
Date2 January 2005 21:38
Thanks for your help Tarquin, I implement the appendChild Method as you said
and works perfectly, well really almost perfect because the first row
inserted looks great, but the second one doubles the last cell width, and
the next one the same, Im pretty sure that is a mistake into my code, but I
can not see it. Lol!!! Here's the code:

	
"var rowElem				=
document.createElement(\"tr\");\n"	+	
	
"var imgElem				=
document.createElement(\"img\");\n"	+
	
"var celElem1				=
document.createElement(\"td\");\n"	+
	
//"rowElem.style.width		=	\"290px\";\n"	+
	
"celElem1.style.width		=	\"118px\";\n"	+
	
"celElem1.style.textAlign 	=	\"center\";\n" +
	
"celElem1.setAttribute('class',\""+ this.ClaseItem +"\");\n" +
	
"celElem1.appendChild(document.createTextNode(descripcion));\n" +
	
"rowElem.appendChild(celElem1);\n" +
	
"var celElem2				=
document.createElement(\"td\");\n"+
	
"celElem2.style.width		=	\"56px\";\n" +
	
"celElem2.style.textAlign 	=	\"center\";\n" +
	
"celElem2.appendChild(document.createTextNode(cantidad));\n" +
	
"celElem2.setAttribute('class',\""+ this.ClaseItem +"\");\n" +
	
"rowElem.appendChild(celElem2);\n" +
	
"var celElem3				=
document.createElement(\"td\");\n"+
	
"celElem3.style.width		=	\"66px\";\n" +
	
"celElem3.style.textAlign 	=	\"center\";\n"+
	
"celElem3.appendChild(document.createTextNode(\"$\" +
FormatoN(precio,\".\")));\n" +
	
"celElem3.setAttribute('class',\""+ this.ClaseItem +"\");\n" +
	
"rowElem.appendChild(celElem3);\n" +
	
"var celElem4				=
document.createElement(\"td\");\n" +
	
"celElem4.style.width		=	\"50px\";\n" +
	
"celElem4.style.textAlign 	=	\"center\";\n" +
	
"celElem4.style				=	\"CURSOR: hand\";\n" +
	
"celElem4.appendChild(imgElem);\n" +			
	
"imgElem.src				=	\"" +
this.RutaImagenReprobar + "\";\n"		+

	
"imgElem.style.width		=	\"20px\";\n" +
	
"imgElem.style.height		=	\"20px\";\n" +
	
"imgElem.setAttribute('onclick',\"borrardecanasta('\"+ codigo +\"','\" +
cantidad +\"','\" + precio + \"')\");\n"	+

	
"imgElem.setAttribute('id',\"btn\" + codigo);\n" +

	
"celElem4.setAttribute('class',\""+ this.ClaseItem +"\");\n" +
	
"rowElem.appendChild(celElem4);\n" +				
	
"document.getElementById(\"" + this.TablaCanasta +
"\").appendChild(rowElem);\n";  

Thanks for your help man, It was so precise and helpful!!!

Cordially,


Camilo Vergara Muñoz
FromCamilo Vergara Muñoz
ToMe
SubjectRe: Inserting Rows by Code
Date3 January 2005 14:48
Tarquin, hello again

Excuse me If I disturb you peace the last days, but Im still having problems
developing for IEMAC5.5 (really sucks!!), But I redefine the issue, it
appears to be happening when I try to insert a IMG element into a TD
element, the first time inserts good but when insert it once the cell
duplicates its width.. Theres a knowing issue inserting IMG tag element in
IEMAC?

Thanks In Advance.

PH: Forgive my poor English...


Camilo Vergara Muñoz
FromMe
ToCamilo Vergara Muñoz
SubjectRe: Inserting Rows by Code
Date8 January 2005 23:35
Camilo,

> Theres a knowing issue inserting IMG tag element in
> IEMAC?

I do not know one, and I cannot see anything wrong in your code. Maybe you
found a new bug :(
This site was created by Mark "Tarquin" Wilton-Jones.
Don't click this link unless you want to be banned from our site.