I want to allow the user to click the start point, and then click the end point and be able to manipulate various form elements between the two selected points.
A page is a table with many rows, and each row contains relevant information for managing / saving the answer to a question in this row. Each line has a hidden input for the value, as well as a Yes / No button, mainly for unskilled users. A TD cell with a question allows the user to click or switch between Yes, No, Empty. So basically I left the switches on the page to show "Yes / No", and use a hidden field to store the value (1,0, -1)
This is what I use to set the answer when the question cell is clicked.
$(".question").bind("click dblclick", function(e) {
var newClassName = "AnswerUnknown";
var hiddenAnswerId = $(this).attr('id').replace("question", "answer");
var answer = parseInt($("#" + hiddenAnswerId).val());
var newValue;
switch (answer) {
case -1:
newClassName = "AnswerCorrect";
newValue = 1;
$("#" + $(this).attr('id').replace("answer", "radioYes")).attr('checked', 'checked');
$("#" + $(this).attr('id').replace("answer", "radioNo")).attr('checked', '');
break;
case 1:
newClassName = "AnswerWrong";
newValue = 0;
$("#" + $(this).attr('id').replace("answer", "radioYes")).attr('checked', '');
$("#" + $(this).attr('id').replace("answer", "radioNo")).attr('checked', 'checked');
break;
default:
newClassName = "AnswerEmpty";
newValue = -1;
$("#" + $(this).attr('id').replace("answer", "radioYes")).attr('checked', '');
$("#" + $(this).attr('id').replace("answer", "radioNo")).attr('checked', '');
}
$("#" + hiddenAnswerId).val(newValue);
$(this).removeClass().addClass(newClassName);
});
Now I want to allow the user to click on the start point, and this answer will fill the whole next question to the place where he clicked on the second element. There may be 10 questions, or 20 questions, this is an unknown variable. It can have a page with 130 questions, and 20 questions in a row can be "Yes." As indicated above, each row has a Question cell, and the cell has an element cell.
I know how to set the start element and the end element based on the jquery selector / function associated with the click / dblclick event below.
I am not sure how to navigate the dom or select all the elements that I need to manipulate between the two selected points on the page.
var StartItem;
var EndItem;
$(".item").bind("click dblclick", function(e) {
var StartClassName = "AnswerUnknown";
var EndClassName = "AnswerUnknown";
var StartAnswerId;
var EndAnswerId;
var StartAnswer;
if (StartItem === undefined) {
StartItem = this;
StartAnswerId = $(this).attr('id').replace("item", "rs");
StartAnswer = parseInt($("#" + StartAnswerId).val());
}
else {
if (EndItem === undefined) {
EndItem = this;
EndAnswerId = $(this).attr('id').replace("item", "rs");
EndAnswer = parseInt($("#" + EndAnswerId).val());
}
}
if (StartItem == this) {
$(this).removeClass().addClass(StartClassName);
}
if (EndItem == this) {
$(this).removeClass().addClass(EndClassName);
}
});