JQuery Selectors

$(function () {

function ShowNextRow($InputElement) {
var $CurrentRow = $InputElement.closest(‘tr’);
if ($InputElement.hasClass(‘disableall’)) {
var inputs = $CurrentRow.find(“input”);
var selects = $CurrentRow.find(“select”);
inputs.attr(‘disabled’, ‘disabled’);
selects.attr(‘disabled’, ‘disabled’);
}

if ($InputElement.hasClass(‘jump’)) {
var $JumpToId = $InputElement.attr(‘data-jumptoid’);
$(‘tr#’ + $JumpToId).removeClass(‘Invisible’);
}
else {
$CurrentRow.next(‘tr’).removeClass(‘Invisible’);
}
}
$(‘.handle-positive-radio’).click(function () {
var $InputElement = $(this);
var $IsRequiredToSave = $InputElement.attr(‘data-requiretosave’);
if ($IsRequiredToSave==’yes’) {
var data = {};
data.columnname = $InputElement.attr(‘data-columnname’);
data.datatype = $InputElement.attr(‘data-datatype’);
data.value = $InputElement.attr(‘value’);
SubmitAjax(data);
}

ShowNextRow($InputElement);

});

//$(‘.handle-positive-radio’).not(‘.exception’).click(function () {
// // alert(‘hi’);
// var $element = $(this);
// var columunName = $element.attr(‘data-columnname’);
// var dataType = $element.attr(‘data-datatype’);
// var value = $element.attr(‘value’);
// var data = {};
// data.columnname = columunName;
// data.datatype = dataType;
// data.value = value;
// SubmitAjax(data);
// ShowNextRow($element);
//});
//$(‘.handle-positive-radio.exception’).click(function () {
// var $element = $(this);
// var columunName = $element.attr(‘data-columnname’);
// var dataType = $element.attr(‘data-datatype’);
// var value = $element.attr(‘value’);
// var nextTrToSelect = $element.attr(‘data-nexttrid’);
// var data = {};
// data.columnname = columunName;
// data.datatype = dataType;
// data.value = value;
// SubmitAjax(data);
// ShowNextRowWithId($element,nextTrToSelect);
//});

$(document).on(‘click’, ‘.handle-negative-radio’, function (e) {

var $InputElement = $(this);
var $IsRequiredToSave = $InputElement.attr(‘data-requiretosave’);
if ($IsRequiredToSave == ‘yes’) {
var data = {};
data.columnname = $InputElement.attr(‘data-columnname’);
data.datatype = $InputElement.attr(‘data-datatype’);
data.value = $InputElement.attr(‘value’);
SubmitAjax(data);
}

$InputElement.closest(‘h6’).next(‘h5’).removeClass(‘Invisible’);

ShowNextRow($InputElement);
});

//$(document).on(‘change’, ‘.handle-combo’, function (e) {
// var $element = $(this);
// var columunName = $element.attr(‘data-columnname’);
// var dataType = $element.attr(‘data-datatype’);
// var value = $element.val();
// var data = {};

// data.columnname = columunName;
// data.datatype = dataType;
// data.value = value;
// SubmitAjax(data);
// ShowNextRow($element);
//});

$(‘.handle-combo’).not(‘.Exception’).change(function () {
var $element = $(this);
var columunName = $element.attr(‘data-columnname’);
var dataType = $element.attr(‘data-datatype’);
var value = $element.val();
var data = {};

data.columnname = columunName;
data.datatype = dataType;
data.value = value;
SubmitAjax(data);
ShowNextRow($element);

});

$(‘.handle-combo.Exception’).change(function () {
var $element = $(this);
var columunName = $element.attr(‘data-columnname’);
var dataType = $element.attr(‘data-datatype’);
var value = $element.val();
var data = {};

data.columnname = columunName;
data.datatype = dataType;
data.value = value;
SubmitAjax(data);
ShowNextRowWithId($element, ‘finaltr’);

});

//function ShowNextRow(element) {

// var rowIndex = $(‘#QuestionTable tr’).index(element.closest(‘tr’));
// var currentTrPosition = rowIndex + 1;
// var currentTR = $(“#QuestionTable tr:nth-child(” + currentTrPosition + “)”);

// var inputs = currentTR.find(“input”);
// var selects = currentTR.find(“select”);
// inputs.attr(‘disabled’,’disabled’);
// selects.attr(‘disabled’, ‘disabled’);
// nextTrPosition = rowIndex + 2;
// //var nextTR = $(“#QuestionTable tr:nth-child(” + nextTrPosition + “)”);
// var nextTR =$(element).closest(‘tr’).next(‘.Invisible’).not(‘.ExceptionTr’);
// console.log(nextTR);
// nextTR.removeClass(‘Invisible’);
//}

function ShowNextRowWithId(element, nextTrId) {

var rowIndex = $(‘#QuestionTable tr’).index(element.closest(‘tr’));
var currentTrPosition = rowIndex + 1;
var currentTR = $(“#QuestionTable tr:nth-child(” + currentTrPosition + “)”);

var inputs = currentTR.find(“input”);
var selects = currentTR.find(“select”);
inputs.attr(‘disabled’, ‘disabled’);
selects.attr(‘disabled’, ‘disabled’);
// var nextTR = $(“#QuestionTable tr#good”);

var trToShow = $(‘tr#’ + nextTrId);
trToShow.removeClass(‘Invisible’);

}

function SubmitAjax(data) {
$.ajax({
type: ‘POST’,
url: ‘http://localhost:50929/QuestionOne/SubmitAnswer/’,

contentType: ‘application/json; charset=utf-8’,
data: JSON.stringify({data:data}),
dataType: ‘json’,
beforeSend: function () {

},
success: function (response) {

},
error: function (request, status, error) {
},
complete: function () {
}
});
}
});

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s