Learning JavaScript, jQuery & JSON

My goal is to represent a certain total value of everything in a table field in a grid based on specific conditions like a date range.

here is what I did to capture the date range from two input fields:

<input type="date" id="startdate"/>
<input type="date" id="enddate"/>

var dateArray = '[$('#startdate').val(),$('#enddate').val()]';
var dateJSON = JSON.stringify(dateArray);

      

Now my problem is my first JSON script. He has no idea what should be in the column of the grid, where he should be.

  {
  "Type": "condition",
  "Data": {
    "Type": "And",
    "Expressions": [{
      "Type": "compare",
      "Data": {
        "Type": "GreaterThan",
        "Left": {
          "Type": "field",
          "Data": {
            "Table": "table",
            "Field": "date"
          }
        },
        "Right": {
          "Type": "constant",
          "Data": "dateArray"
        }
      }
    }, {
      "Type": "compare",
      "Data": {
        "Type": "LessThanOrEqual",
        "Left": {
          "Type": "field",
          "Data": {
            "Table": "table",
            "Field": "date"
          }
        },
        "Right": {
          "Type": "constant",
          "Data": "dateArray"
        }
      }
    }]
  }

      

Anything that could help would be greatly appreciated.

+3


source to share


1 answer


Your code is almost right, it just needs a little fix. The correct syntax for declaring an array is:

var arr = [value1, value2, ...]



$('#run').click(function () {
    var dateArray = [$('#startdate').val(), $('#enddate').val()];
    var dateJSON = JSON.stringify(dateArray);
    alert(dateJSON);
});
      

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="date" id="startdate" />
<input type="date" id="enddate" />
<button id="run">Run</button>
      

Run code


+1


source







All Articles