SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Member
    Join Date
    Apr 2004
    Location
    Nice
    Posts
    9
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question JavaScript + DOM: swapNode(): How to swap nodes ... problem

    Hi guys,

    I have spent my day trying to figure out how I could swap nodes in my HTML page.

    Basically I have a table with any given amount of rows.
    In each of these rows I have a checkbox.
    The user can select any 2 rows with these checkboxes and click on a "swap us!" button to swap them (that is the first row takes the pace of the second and vice versa) - this shall be performed on the client side with JavaScript.

    I have seen that the DOM has a method called swapNode() but I cannot get it work property for 2 reasons:

    1) It looks **like** it is not portable (NS vs. IE) (accoring to what I read somewhere on the web)

    2) I am not a champ. in DOM/JavaScript, but I gave a try in doin' it with the other DOM methods (appendChild() bla bla bla) without success - I am crap

    I hope some genius out there is going to be able to provide me with some code! Don't ask for mine, I have tried again and again from scratch so many times that my keyboard could let me down!

    Thanks!

  2. #2
    SitePoint Guru
    Join Date
    Mar 2004
    Location
    Earth
    Posts
    406
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    swapNode is not a real DOM method, it's an IE-proprietary extension.

    Try the insertBefore method - http://www.mozilla.org/docs/dom/domr..._el_ref47.html

  3. #3
    SitePoint Member
    Join Date
    Apr 2004
    Location
    Nice
    Posts
    9
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Wink

    Thanks for this, but I knew this - my problem is that I am not able to code a swapNode()-like function using other DOM functions() (I am not a professional developer ... Just try to do something nice here).

    Can anybody help?

  4. #4
    SitePoint Wizard silver trophy
    Join Date
    May 2003
    Posts
    1,843
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ::: certified wild guess :::

  5. #5
    SitePoint Member
    Join Date
    Apr 2004
    Location
    Nice
    Posts
    9
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for your quick answer Adios, However my case is somehow a bit more difficult (?). I have found someone with exactely the same question as mine on the another forum on the net (he didn't get an answer from anybody as far as I know), and here is his (very clear) description:-

    --------------------------------------------------------------------------------
    DOM: My SwapNodes() for tables almost works, need some help on this:

    want to used JavaScript + DOM in order to dynamically move the rows of a table up and down.

    I have found a piece of code (enclosed) from the internet that that is quite portable: a redefinition of the IE's swapNode() DOM function.

    Now the deal is (and it might sound simple) that I want to move the rows up and down, but two steps at the time - and cannot fgure out how to do that.

    Here is what the final UI should look like:-

    ---------------------------------------------------
    | This must stay unchanged |
    ---------------------------------------------------
    | A | | moveDown |
    ---------------------------------------------------
    | This must stay unchanged |
    ---------------------------------------------------
    | B | moveUp | moveDown |
    ---------------------------------------------------
    | This must stay unchanged |
    ---------------------------------------------------
    | C | moveUp | moveDown |
    ---------------------------------------------------
    | This must stay unchanged |
    ---------------------------------------------------
    | D | moveUp | moveDown |
    ---------------------------------------------------
    | This must stay unchanged |
    ---------------------------------------------------
    | E | moveUp | |
    ---------------------------------------------------

    ....
    I would really appreciate if someone could have a look at it and propose something that could help me.

    INDICATION: In my table, each 'TR' tag that can move up/down is associated to a id, in case it is of any help to resolve this problem (e.g. to detect only the TRs that have an id != nill).
    --------------------------------------------------------------------------------

    THANKS ALL FOR YOUR HELP.

    Joey

  6. #6
    SitePoint Member
    Join Date
    Apr 2004
    Location
    Nice
    Posts
    9
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question

    Actually, if you go to the following address you have a more readable format of the problem (with the real tabe, and look and feel) ...

    http://www.jguru.com/forums/view.jsp?EID=1166195

    Thanks

  7. #7
    SitePoint Wizard silver trophy
    Join Date
    May 2003
    Posts
    1,843
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That's a tall order, requiring a complete script (or an api routine, already debugged). See if this is of any use; Mike Hall's excellent tutorial, while not entirely germane, might clear a few things up too.
    ::: certified wild guess :::

  8. #8
    SitePoint Wizard silver trophy
    Join Date
    May 2003
    Posts
    1,843
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    pivoiner....

    Just took another look at this thread...the original description of what you needed is considerably different (I think) than the other post you referenced.

    Could you clear this up? An exact description of what you wanted to do (a sample of HTML would help a lot) might suggest a solution.
    ::: certified wild guess :::


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
  •