Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 193715
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T16:32:02+00:00 2026-05-11T16:32:02+00:00

I am trying to setup a function to allow moving ‘up’ and ‘down’ of

  • 0

I am trying to setup a function to allow moving ‘up’ and ‘down’ of a table row in a form. The number of table rows is dynamic — the user can hit a button to add additional rows. There are multiple fields in each table row. There is a header row and footer row with different class names, hence the check of hasClassName.

I first wrote this function successfully for use with Prototype 1.6 before realizing I need for it to work with version 1.5.1. We will be upgrading to the latest version of Prototype when time is available for testing, but I need this to work under the our project’s current version.

The main problem is that in 1.5 you can’t just insert an Element as the content of an insertion. This means I need the HTML of the Element I want to insert. This brings up the issue that when I access the HTML for the element (variable “insertHTML”) this is the original HTML and does not include the info entered into the related form elements by the user.

Any help would be greatly appreciated.

moveDataDef: function(num, dir) {
    var targRow = $('dataDefItem'+num);
    var content = targRow.innerHTML;
    var siblings;
    var insertHTML = targRow.inspect() + targRow.innerHTML + '</tr>';

    if(dir == 'up')
        siblings = targRow.previousSiblings();
    else
        siblings = targRow.nextSiblings();

    if (siblings[0].hasClassName('dataDefItem')) {
        targRow.remove();
        if(dir == 'up')
            new Insertion.Before(siblings[siblings.length - 1].id, targRow);
        else
            new Insertion.After(siblings[0].id, targRow);
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-11T16:32:02+00:00Added an answer on May 11, 2026 at 4:32 pm

    I guess, you could use part of this code, to replace your lower if block. It use native DOM function, ie insertBefore():

    if (siblings[0].hasClassName('dataDefItem')) {
      var targetParent = targRow.parentNode;
      var sibling = siblings[0];
    
      if(dir == 'up'){
        targRow.remove();
        targetParent.insertBefore(targRow, sibling);
      } else {
        sibling.remove();
        targetParent.insertBefore(sibling, targRow);
      }
    }
    

    For your reference, if you are interested, this is my POC code:

    <table id="tb1">
    <tbody>
    <tr id="tr1"><td>1</td></tr>
    <tr id="tr2"><td>2</td></tr>
    <tr id="tr3"><td>3</td></tr>
    </tbody>
    </table>
    
    <script type="text/javascript">
    /* <![CDATA[ */
    (function(){
    var trr3 = $('tr3');
    var tp = trr3.parentNode; 
    var trr1 =trr3.previousSiblings();
    trr3.remove();
    tp.insertBefore(trr3, trr1[0]);
    })();
    /* ]]> */
    </script>
    

    Thanks.

    Update: Fix typo (missing ‘{‘ and ‘}’).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 168k
  • Answers 168k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I ended up using conditional comments in my javascript file.… May 12, 2026 at 1:40 pm
  • Editorial Team
    Editorial Team added an answer Found it: 'rowCount' is the property to change. It defaults… May 12, 2026 at 1:40 pm
  • Editorial Team
    Editorial Team added an answer Yes, it is possible, use the below code with Attribute… May 12, 2026 at 1:40 pm

Related Questions

I am trying to setup a function to allow moving 'up' and 'down' of
Consider the following setup: A windows PC with a LAN interface and a WiFi
I am trying to set up a page that will allow the user to
I am trying to create a custom CStatic control in vc++ and have a
Im trying to export a .dmp of an oracle database but am getting the

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.