Email conversation
From | Karan S. Mohite |
To | Me |
Subject | Mozilla Javascript Problem |
Date | 13 September 2005 17:29 |
hi
I have a table with rows containing checkboxes, text boxes , links etc.
I have written a javascript to following operations on the tables
Row-> Move One Up, One Down, First, Last.
It works fine in I.E but in Mozilla there is a problem.
say if I deselect a checkbox for a row
then use one up operation on it
the rows get swapped BUT
the checkbox although was unticked gets ticked after the operation
I use innerHTML to swap the contents of the rows.
Its really important for me to get this working for the next realease.
I hope to get a response from you soon
Regards
karan
From | Me |
To | Karan S. Mohite |
Subject | Re: Mozilla Javascript Problem |
Date | 13 September 2005 17:46 |
> It works fine in I.E but in Mozilla there is a problem.
what about in Opera?
From | Karan S. Mohite |
To | Me |
Subject | Re: Mozilla Javascript Problem |
Date | 13 September 2005 18:18 |
Attachment | script that reordered table rows using innerHTML |
its the same the checked status doesnot get set accordingly
I am attaching a test script, u may not open it if you dont want to.
thanks
Karan
From | Me |
To | Karan S. Mohite |
Subject | Re: Mozilla Javascript Problem |
Date | 13 September 2005 18:39 |
Karan,
> its the same the checked status doesnot get set accordingly
Ok, this all makes sense. In fact IE is weird to allow it.
You are not using DOM. You are using innerHTML. innerHTML does not preserve
the status. It reads the HTML. The HTML contains the checked attribute, so
that's what innerHTML returns. You then write a new row containing the
innerHTML. It is not the old row, it is a new one.
What you want to do is to move the old row - that way, it should retain its
exact state without confusing anything. No messing about with innerHTML. Use
DOM methods. insertBefore is the method you want. To move to the top, use
this:
oTBody.insertBefore(theRow,oTBody.rows[0]);
To move to the end, use this:
oTBody.appendChild(theRow);
Mark 'Tarquin' Wilton-Jones - author of http://www.howtocreate.co.uk/
From | Karan S. Mohite |
To | Me |
Subject | Re: Mozilla Javascript Problem |
Date | 13 September 2005 19:33 |
Attachment | modified script |
i am attaching a sample script, it seems the results are weird , I am not
sure what I am doing wrong it. I fyou could please take a look
regards
karan
From | Me |
To | Karan S. Mohite |
Subject | Re: Mozilla Javascript Problem |
Date | 13 September 2005 20:29 |
Karan,
I am looking at your 'MvOneDown' function, since that is the only one you have
prepared for now;
var z = tbBody.rows[i-1];
no it isn't. what if i is 0 ? there is no such thing as row -1.
You also seem to have your directions reversed. z should be row i+2.
Aditionally, the parent of the row is _not_ the table. it is the tbody
element, which browsers are required to create, even if you did not specify
one.
http://www.howtocreate.co.uk/tutorials/javascript/domtables
This function replaces your MvOneDown function, and it should give you what
you need to rewrite the other functions too:
function MvOneDown(i,f) {
var tbBody = document.getElementsByTagName('table')[0].tBodies[0];
var x = tbBody.rows; // get all rows in x
var y = x[i];
var z = x[i+2];
if( i != x.length - 1 ) {
tbBody.insertBefore(y,z);
} else {
//this should not be needed, since insertBefore should
//act like appendChild if the second argument is null
//however, that fails in IE Mac,
tbBody.appendChild(y);
}
}
Tarquin
From | Karan S. Mohite |
To | Me |
Subject | Re: Mozilla Javascript Problem |
Date | 13 September 2005 20:44 |
hi
i am not sure why but the function you sent to me gives error as
invalid argument in I.E and
some uncaught exception Node was not found in Mozilla and Opera
thanks
karan
From | Me |
To | Karan S. Mohite |
Subject | Re: Mozilla Javascript Problem |
Date | 13 September 2005 20:52 |
Karan,
> i am not sure why but the function you sent to me gives error as
> invalid argument in I.E and
> some uncaught exception Node was not found in Mozilla and Opera
Well, it worked in the copy I have, so I guess I need to see your page to
work out why it fails.
Tarquin
From | Karan S. Mohite |
To | Me |
Subject | Re: Mozilla Javascript Problem |
Date | 13 September 2005 21:50 |
Attachment | updated script |
please find the file attached
Karan,
> please find the file attached
I have attached a version that should work as required
Tarquin
From | Karan S. Mohite |
To | Me |
Subject | Re: Mozilla Javascript Problem |
Date | 17 September 2005 16:32 |
hi
sorry I was busy with school for a couple of days so was unable to reply
to you. Thank you a lot for you r help. I really appreciate the way u took
time out of your busy schedule and answered by question.
thank you again
Karan