0

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>
CloudyKooper
  • 727
  • 3
  • 19
  • 47
  • Please see http://stackoverflow.com/questions/17856846/comparing-two-arrays-in-jquery , may be useful – Bhushan Kawadkar May 14 '14 at 05:18
  • So I checked out the example here: http://stackoverflow.com/questions/17856846/comparing-two-arrays-in-jquery... and it seems there are some characters that are different when compared. But how can that be when I'm using the same loop to push strings into arrays? Also why do you think it's comparing characters instead of strings? – CloudyKooper May 14 '14 at 05:34
  • ... if you read my comment carefully I said "may be useful". It means this is not exact what you require but it may suggest some idea. – Bhushan Kawadkar May 14 '14 at 05:42

0 Answers0