1

Bellow I show some example. How I can add some jquery expression into onCalculate() function.

var obj = {
    id: '',
    onCalculate: function () {
       var _date = $("#date").val();  //jquery expression doesn't work here
        // how I can do it?
    }
};

8
  • 1
    what do you mean by jquery expression? Commented Mar 15, 2018 at 6:44
  • What code you have tried? What error message is shown? Commented Mar 15, 2018 at 6:45
  • gurvinder372, I'd like to call something like this var _date = $("#date").val(); Commented Mar 15, 2018 at 6:47
  • Your idea is to write a function with the jquery expression? Commented Mar 15, 2018 at 6:49
  • Triet Pham, yep. What do you think about it? Commented Mar 15, 2018 at 6:50

1 Answer 1

1

You can call function like this. See working snippet.

var obj = {
  id: '',
  onCalculate: function() {
    var _date = $("#date").val(); //jquery expression doesn't work here
    // how I can do it?
    console.log(_date);
  }
};
$("#date").keyup(function() {
  obj.onCalculate();
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type='text' id='date' />

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

2 Comments

Thank a lot.Validate answer if helpful for future. Happy Coding :)
Thanks, Have a nice day!

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.