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

  • SEARCH
  • Home
  • 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 7610053
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T01:19:33+00:00 2026-05-31T01:19:33+00:00

here i have the following html, as it is basically match the following concept,

  • 0

here i have the following html, as it is basically match the following concept, i need to able drag and drop the AnswerSide Cells. Only Answers Side cells can me moved up and down. and after moving, we need to get the Text of the answer and its position. (as i am doing in asp.net, and the table will be genrated behind the code.)

  1. User can move up and down the Answers. (only Answers can be moved)
  2. We need to retrive the text, and its position
  3. We need to save it in DB

can any one tell me how to do this. i tried Jquery Ui sortables, as i am not getting it. as i am beginner, can anybody help me to solve the problem.

I updated with HtmlTable, and Div Layout, however now any one can help me to solve, in either way

JSFIDDLE Link for Following HTML

Jsfiddle for Div Layout

<html>
    <table border="1">
    <tr>
        <td>QuestionSide</td>
        <td>Answer Side</td>
    </tr>
        <tr>
            <td>Question 1  </td>
            <td><div> Ans1 </div> </td> // this div is needed to 
        </tr>
        <tr>
            <td>question 2 </td>
            <td><div > Ans2  </div> </td>
        </tr>
        <tr>
            <td> question 3</td>
            <td><div> Ans3  </div> </td>
        </tr>
        <tr>
            <td> question 4</td>
            <td><div> Ans4  </div> </td>
        </tr>
        <tr>
            <td> question 5 </td>
            <td><div> Ans5  </div> </td>
        </tr>
    </table>
</html>
  • 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-31T01:19:35+00:00Added an answer on May 31, 2026 at 1:19 am

    Well. I agree with @tereško You should use divs. But even then, you will be faced with the same issues. You could just put a sortable next to another set of divs, but a sortable may not work for you especially if the answer rows need to match the height of the question rows.

    Here is the code that you need to drag and drop answers.
    HTML:

    <table border="1" id="qatable">
    <tr>
        <td>QuestionSide</td>
        <td>Answer Side</td>
    </tr>
        <tr>
            <td>Question 1  </td>
            <td><div class="answer answer1"> Ans1 </div> </td>
        </tr>
        <tr>
            <td>question 2 </td>
            <td><div class="answer answer2"> Ans2  </div> </td>
        </tr>
        <tr>
            <td> question 3</td>
            <td><div class="answer answer3"> Ans3  </div> </td>
        </tr>
        <tr>
            <td> question 4</td>
            <td><div class="answer answer4"> Ans4  </div> </td>
        </tr>
        <tr>
            <td> question 5 </td>
            <td><div class="answer answer5"> Ans5  </div> </td>
        </tr>
    </table>
    <br /><br />
    <button onclick="alert($('.answer').index($('.answer1'))+1);">Get position of answer 1</button><br />
    <button onclick="alert($('.answer').index($('.answer2'))+1);">Get position of answer 2</button><br />
    <button onclick="alert($('.answer').index($('.answer3'))+1);">Get position of answer 3</button><br />
    <button onclick="alert($('.answer').index($('.answer4'))+1);">Get position of answer 4</button><br />
    <button onclick="alert($('.answer').index($('.answer5'))+1);">Get position of answer 5</button><br />
    <br /><br>
    <button onclick="alert($('.answer').eq(0).html());">Get answer of question 1</button><br />
    <button onclick="alert($('.answer').eq(1).html());">Get answer of question 2</button><br />
    <button onclick="alert($('.answer').eq(2).html());">Get answer of question 3</button><br />
    <button onclick="alert($('.answer').eq(3).html());">Get answer of question 4</button><br />
    <button onclick="alert($('.answer').eq(4).html());">Get answer of question 5</button><br />
    

    And here is the jQuery code. Make sure you have included the jquery and jquery ui script files.

    $(document).ready(function(e) {
        $('.answer').draggable({
            axis: 'y',
            opacity: 0.5,
            containment: $('#qatable'),
            revert: true,
            revertDuration: 0,
            distance: 10,
            cursor: 'pointer'
        }).droppable({
            accept: '.answer',
            tolerance: 'pointer',
            drop: function(event, ui) {
                ui.droppable = $(this);
                var answers = $('#qatable').find('.answer');
                toindex = answers.index(ui.droppable);
                fromindex = answers.index(ui.draggable);
                var placeholder = $('<div id="placeholder">&nbsp;</div>').insertBefore(ui.droppable); // Placeholder
                if (toindex < fromindex) { // Moving an answer up
                    for (var i=toindex;i<fromindex;i++) { 
                        answers.eq(i).insertBefore(answers.eq(i+1)); // Shift everything down
                    }
                    ui.draggable.insertBefore(placeholder); // Move the draggable answer to where the other one was
                    placeholder.remove();
                } else { // Moving the answer down
                    for (var i=toindex;i>fromindex;i--) { 
                        answers.eq(i).insertBefore(answers.eq(i-1)); // Shift everything up
                    }
                    ui.draggable.insertBefore(placeholder); // Move the draggable answer to where the other one was
                    placeholder.remove();
                }
            }
        });
    });
    

    Whether you actually use divs or table cells, is irrelevant. The code still works in either divs or table cells. All you need to do after that is style the table cells.

    To get the position of an answer, just use the index method.

    var pos = $('.answer').index($('.answer1'))+1;
    

    To get an answer for a question, just use the eq method. Just know that it is 0 based so the answer to question 1 is eq(0) and the answer to question 2 is eq(1), etc…

    var answer = $('.answer').eq(0).html();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following strange situation here I need some help with: I am
I have following code: public static void ProcessStep(Action action) { //do something here if
I have the following string: cn=abcd,cn=groups,dc=domain,dc=com Can a regular expression be used here to
I have the following code. Here I am matching the vowels characters words :
Say I have the following class: class Foo { // ctor etc here public
I have the following code, which compiles but doesn't bring back any data. Here
suppose you have the following structure: #include <windows.h> // BOOL is here. #include <stdio.h>
Here's a fun one I've been trying to figure out. I have the following
This is probably a silly question, but here it goes.Imagine you have the following
Right, starting to go crazy here. I have the following code: var query =

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.