3

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

here's 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 on my first JSON script. It's not presenting what it should on the grid column where it should.

  {
  "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 very much appreciated.

3
  • Try to remove the wrapping single quotes in your dateArray declaration, like this: var dateArray = [$('startdate'),$('enddate')]; Commented May 20, 2015 at 3:45
  • It's an element. Thanks for noticing. I forgot to put # & val() on them but it still isn't working. Commented May 20, 2015 at 4:33
  • No, I meant the single quotes surrounding your array declaration. Commented May 20, 2015 at 5:16

1 Answer 1

1

Your code is almost right, it just need a little fix. The right 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>

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks! My only problem now is the JSON arguments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.