How to correctly display the numbers for each table row added
I have a slight problem with my application. What is suppose to happen is that when the user selects an option and answer and submits it, it will add a new row. The problem is that the question number is suppose to be +1 every time a new row is created so that it goes question number 1 for row 1, question number 2 for row 2 and etc. Instead it is just displaying the number 1 for each row under the question number column.
How can I get it to display 1,2,3 etc for the question No for each row added.
To use the jsfiddle app do this:
open grid and select option "3", type in the number 1 in the "Number of Answers" text-box and select Button "A". Then click on "Add Question" and a new row is added.
Code is in jsfiddle, click here
You were missing an opening <form> tag
forked fiddle: http://jsfiddle.net/ubS6c/
You can use
var qnum = $('#qandatbl').find("tr").length - 1;
You can count the number of elements with a particular class as follows:
var qnum = jQuery('.qid').length; var html = jQuery("<tr><td class='qid'>" + qnum + "</td></tr>");
- did you look at jqgrid? http://www.trirand.com/blog/
Typically I would solve this sort of thing with jqgrid and ajax call-backs. Some logical back-end can then be used to do more of the calculation, separating out the separation of interaction, view, control and domain.