By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,472 Members | 1,270 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,472 IT Pros & Developers. It's quick & easy.

missing the row id after sort

P: 6
I have two iframes on a page that display a table which contain checkboxes that when ticked delete the row.

Everything works fine expect when I sort one of the tables in the iframe. I set the id attribute each time and when I view the HTML in a debugger the row id is set to the new id.

When I select the checkbox to delete the sorted row using

Expand|Select|Wrap|Line Numbers
  1. var frameName = document.getElementById('view1').contentWindow;
  2. frameName.document.getElementById(rowId).rowIndex;
I get an object error, any idea’s ?
Oct 11 '07 #1
Share this Question
Share on Google+
9 Replies


dmjpro
100+
P: 2,476
I have two iframes on a page that display a table which contain checkboxes that when ticked delete the row.

Everything works fine expect when I sort one of the tables in the iframe. I set the id attribute each time and when I view the HTML in a debugger the row id is set to the new id.

When I select the checkbox to delete the sorted row using

var frameName = document.getElementById('view1').contentWindow;
frameName.document.getElementById(rowId).rowIndex;

I get an object error, any idea’s ?

Alert this "frameName.document.getElementById(rowId)".
See whether it returns "undefined".
If possible, send the "Sorting" code.

Debasis Jana.
Oct 11 '07 #2

P: 6
on the alert returned null

Expand|Select|Wrap|Line Numbers
  1. function fillArray(view ,column){
  2.   var frameName = document.getElementById(view).contentWindow;
  3.   for (var i = 0; i < frameName.document.getElementById('View').rows.length; i++){
  4.     var Col1 = frameName.document.getElementById('View').rows[i].cells[0].innerHTML;
  5.     var Col2 = frameName.document.getElementById('View').rows[i].cells[1].innerHTML;
  6.     var Col3 = frameName.document.getElementById('View').rows[i].cells[2].innerHTML;
  7.     var Col4 = frameName.document.getElementById('View').rows[i].cells[3].innerHTML;
  8.     [Lines.length++] = new Line(col1, col2, col3, col4);
  9.   }
  10.   sortList(view ,column)
  11. }
  12.  
  13. function Lines(col1, col2, col3, col4) {
  14.   this.Col1 = col1;
  15.   this.Col2 = col2;
  16.   this.Col3 = col3;
  17.   this.Col4 = col4;
  18. }
  19.  
  20. function sortTable(view){
  21.   var frameName = document.getElementById(view).contentWindow;
  22.   var counter = Lines.length - 1;
  23.     for (var i = 0; i <= counter; i++){ 
  24.       frameName.document.getElementById('View').rows[i].setAttribute('id', Lines[i].Col1);
  25.       frameName.document.getElementById('View').rows[i].cells[0].innerHTML = Lines[i].Col1;
  26.       frameName.document.getElementById('View').rows[i].cells[1].innerHTML = Lines[i].Col3;
  27.       frameName.document.getElementById('View').rows[i].cells[2].innerHTML = Lines[i].Message;
  28.       frameName.document.getElementById('View').rows[i].cells[3].innerHTML = Lines[i].Col4;
  29.     }
  30.     Lines.length = 0;
  31. }
Oct 11 '07 #3

P: 6
Ooops function Lines should have been Line

Expand|Select|Wrap|Line Numbers
  1. function Line(col1, col2, col3, col4) {
  2. this.Col1 = col1;
  3. this.Col2 = col2;
  4. this.Col3 = col3;
  5. this.Col4 = col4;
  6. }
Oct 11 '07 #4

dmjpro
100+
P: 2,476
on the alert returned null

function fillArray(view ,column){
var frameName = document.getElementById(view).contentWindow;
for (var i = 0; i < frameName.document.getElementById('View').rows.len gth; i++){
var Col1 = frameName.document.getElementById('View').rows[i].cells[0].innerHTML;
var Col2 = frameName.document.getElementById('View').rows[i].cells[1].innerHTML;
var Col3 = frameName.document.getElementById('View').rows[i].cells[2].innerHTML;
var Col4 = frameName.document.getElementById('View').rows[i].cells[3].innerHTML;
[Lines.length++] = new Line(col1, col2, col3, col4);
}
sortList(view ,column)
}

function Lines(col1, col2, col3, col4) {
this.Col1 = col1;
this.Col2 = col2;
this.Col3 = col3;
this.Col4 = col4;
}

function sortTable(view){
var frameName = document.getElementById(view).contentWindow;
var counter = Lines.length - 1;
for (var i = 0; i <= counter; i++){
frameName.document.getElementById('View').rows[i].setAttribute('id', Lines[i].Col1);
frameName.document.getElementById('View').rows[i].cells[0].innerHTML = Lines[i].Col1;
frameName.document.getElementById('View').rows[i].cells[1].innerHTML = Lines[i].Col3;
frameName.document.getElementById('View').rows[i].cells[2].innerHTML = Lines[i].Message;
frameName.document.getElementById('View').rows[i].cells[3].innerHTML = Lines[i].Col4;
}
Lines.length = 0;
}
I think this line will be ...........
Expand|Select|Wrap|Line Numbers
  1. //[Lines.length++] = new Line(col1, col2, col3, col4);
  2. Lines[length++] = new Line(col1, col2, col3, col4);
  3.  
Debasis Jana
Oct 11 '07 #5

dmjpro
100+
P: 2,476
Ooops function Lines should have been Line

function Line(col1, col2, col3, col4) {
this.Col1 = col1;
this.Col2 = col2;
this.Col3 = col3;
this.Col4 = col4;
}
And what is "Lines"??
Please Let me know.

Debasis Jana
Oct 11 '07 #6

gits
Expert Mod 5K+
P: 5,390
heya datapartners,

please use code tags when posting source-code:

[CODE=javascript] your code here [/code]

kind regards
Oct 11 '07 #7

P: 6
Thanks for the tips so far ... from testing it appears that the line below is causing the problem;-

Expand|Select|Wrap|Line Numbers
  1.  frameName.document.getElementById('View').rows[i].setAttribute('id', Lines[i].Col1);
I have commented out the line above from the code and the getElementById() was defined, and could delete a row after the sort was performed but deleted the wrong line.
Oct 11 '07 #8

dmjpro
100+
P: 2,476
Thanks for the tips so far ... from testing it appears that the line below is causing the problem;-

Expand|Select|Wrap|Line Numbers
  1.  frameName.document.getElementById('View').rows[i].setAttribute('id', Lines[i].Col1);
I have commented out the line above from the code and the getElementById() was defined, and could delete a row after the sort was performed but deleted the wrong line.
Check out that whether those Rows updated with desired "ID".

Debasis Jana
Oct 11 '07 #9

P: 6
Problem solved it appears that when the new id was set by the setAttribute from the array it also added white spaces too. I wrote a trim function

Expand|Select|Wrap|Line Numbers
  1.    //---------------------------------------------------------------------------------------->
  2.    //---                               Function Left Trim                         --->
  3.    //---------------------------------------------------------------------------------------->  
  4. function LTrim( value ) {
  5.     var re = /\s*((\S+\s*)*)/;
  6.     return value.replace(re, "$1");
  7. }
  8.  
  9.    //---------------------------------------------------------------------------------------->
  10.    //---                               Function Right Trim                       --->
  11.    //---------------------------------------------------------------------------------------->  
  12. function RTrim( value ) {
  13.     var re = /((\s*\S+)*)\s*/;
  14.     return value.replace(re, "$1");
  15. }
  16.  
  17.    //---------------------------------------------------------------------------------------->
  18.    //---                                  Function Trim                            --->
  19.    //---------------------------------------------------------------------------------------->  
  20. function trim( value ) {
  21.     return LTrim(RTrim(value));
  22. }
  23.  
added it to the


Expand|Select|Wrap|Line Numbers
  1.  
  2. frameName.document.getElementById('View').rows[i].setAttribute('id', trim(Lines[i].Col1));
  3.  
  4.  
and works like a charm, thanks to all concerned.
Oct 11 '07 #10

Post your reply

Sign in to post your reply or Sign up for a free account.