How to pass a variable as an integer to a function?
Let's say I have this function:
- function add(x, y) {
- var add = x + y;
- return add;
- }
And I have this code:
- $(select).change(function(){
- // Get select values
- var select_first = $("select#first").val();
- var select_second = $("select#second").val();
- // Add select values
- var add = add(select_first, select_second);
- $("p#result").html(add);
- });
So let's say the value of select_first is "1", and value of select_second is also "1". But when they are passed to the add function, the returned value is 11 and not 2. So what I understood is that it took the values as strings instead of integers. What should I do so that select_first and select_second are integers instead of string?