I’m really stuck with this jquery solution. I’ve created some arrays where the final objective is to store strings in two arrays newDateAndTime = [] and oldDateAndTime = []. I’ve tried to check if the arrays are similar but no examples I found work so I decided to check each index from one array against the same index of the other array. Using alert I can see that the same data that is in the newDataAndTime is also in oldDateAndTime but when I loop through with this:
if (newDateAndTime[x] == oldDateAndTime[x])
alert("Same");
else alert("Not Same");
I get some elements that are the same and some are not even though when I test these with alerts they show the same data. Is there a better way to compare element to element of two arrays? I apologize for the huge blocks of code but I though I would post it all for completeness. I'm mainly concerned with the end where I try to compare arrays. Thanks for any help.
<script type="text/javascript">
$(function () {
$("#date").datepicker();
$('input[name=date]').datepicker();
var dateInput = $("select[name='searchString']");
var checkedindex = [];
var classdate = [];
var classtime = [];
var dayofclass = [];
var newDateAndTime = [];
var oldDateAndTime = [];
$("input[name='selectedCourses']").each(function (i) {
if (this.checked) {
checkedindex.push(parseInt(i));
}
});
for (var x = 0; x < checkedindex.length; x++) {
var ind = checkedindex[x];
var dateofclass = $(".TextBoxDate:eq(" + ind + ")");
var timeofclass = $(".TextBoxTime:eq(" + ind + ")");
var classday = $("select[name='searchString']:eq(" + ind + ")");
classdate.push(dateofclass);
classtime.push(timeofclass);
dayofclass.push(classday);
oldDateAndTime = dayofclass[x].val() + classtime[x].val();
alert(oldDateAndTime.toString());
}
$("#saveBtn").click(function () {
for (var x = 0; x < checkedindex.length; x++) {
var ind = checkedindex[x];
var dateofclass = $(".TextBoxDate:eq(" + ind + ")");
var timeofclass = $(".TextBoxTime:eq(" + ind + ")");
var classday = $("select[name='searchString']:eq(" + ind + ")");
classdate.push(dateofclass);
classtime.push(timeofclass);
dayofclass.push(classday);
newDateAndTime = dayofclass[x].val() + classtime[x].val();
if (newDateAndTime[x] == oldDateAndTime[x])
alert("Same");
else alert("Not Same");
}
});
});
</script>