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.)
- User can move up and down the Answers. (only Answers can be moved)
- We need to retrive the text, and its position
- 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
<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>
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:
And here is the jQuery code. Make sure you have included the jquery and jquery ui script files.
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.
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 iseq(1)
, etc...