-2

I have following input field for DOB.

<div class="po.pependent">
        <input type="text", class="zm-textbox dob-input-mask" placeholder="dd/mm/yyyy" />,
         <input type="text", class="zm-textbox dob-input-mask" placeholder="dd/mm/yyyy"/></div>

So if enter dob 11/12/1999 and 11/12/1997 the function paymentForm.computeAge return 17 and 19.

Now in JS i am trying to get the value of these to Dob convert them and get the highest age among the two dob entered.

$(".po.pependent:visible input.zm-textbox.dob-input-mask:visible")
        .each(function() {
            paymentForm.computeAge($(this).val())
    })

This paymentForm.computeAge return the calculated age from the given dob date comparing with current system date.

Prabin Poudel
  • 73
  • 1
  • 1
  • 9
  • What is `paymentForm`? What does `computeAge` do? How do you even get the resulting array having no return statements at all? – Yury Tarabanko Aug 30 '17 at 06:36
  • If you're using a particular library, please include a tag for it. This code makes no sense as plain javascript. – RobG Aug 30 '17 at 06:39

2 Answers2

-1

Once you get your array, you can pass it to Math.max.apply() like I have done here with this example array.

var numbers = [1, 2, 3, 4];
console.log(Math.max.apply(null, numbers))
console.log(Math.min.apply(null, numbers))
Get Off My Lawn
  • 34,175
  • 38
  • 176
  • 338
-1

You need to use Math.max. Below are 2 ways of doing it:

console.log(Math.max(17, 19));

var ageArray = [17, 19]
var max_of_array = Math.max.apply(Math, ageArray.map(Number));
console.log(max_of_array)
Milan Chheda
  • 8,159
  • 3
  • 20
  • 35