Karan S. Mohite

Navigation

Skip navigation.

Search

Site navigation

Email conversation

FromKaran S. Mohite
ToMe
SubjectMozilla Javascript Problem
Date13 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
FromMe
ToKaran S. Mohite
SubjectRe: Mozilla Javascript Problem
Date13 September 2005 17:46
> It works fine in I.E but in Mozilla there is a problem.

what about in Opera?
FromKaran S. Mohite
ToMe
SubjectRe: Mozilla Javascript Problem
Date13 September 2005 18:18
Attachmentscript 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
FromMe
ToKaran S. Mohite
SubjectRe: Mozilla Javascript Problem
Date13 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/
FromKaran S. Mohite
ToMe
SubjectRe: Mozilla Javascript Problem
Date13 September 2005 19:33
Attachmentmodified 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
FromMe
ToKaran S. Mohite
SubjectRe: Mozilla Javascript Problem
Date13 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
FromKaran S. Mohite
ToMe
SubjectRe: Mozilla Javascript Problem
Date13 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
FromMe
ToKaran S. Mohite
SubjectRe: Mozilla Javascript Problem
Date13 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
FromKaran S. Mohite
ToMe
SubjectRe: Mozilla Javascript Problem
Date13 September 2005 21:50
Attachmentupdated script
please find the file attached
FromMe
ToKaran S. Mohite
SubjectRe: Mozilla Javascript Problem
Date13 September 2005 18:39
Attachmentworking script that re-orders table rows
Karan,

>   please find the file attached

I have attached a version that should work as required

Tarquin
FromKaran S. Mohite
ToMe
SubjectRe: Mozilla Javascript Problem
Date17 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
This site was created by Mark "Tarquin" Wilton-Jones.
Don't click this link unless you want to be banned from our site.