I have a page with 3 input fields. Of these fields I want to get the max value. What I'd like to achieve is that a user can fill in a field, the value of that field is dynamically added to an array, and also this value be displayed in a textfield if this value is greater than the value of the other two input fields. I'd like to be able to do this without the onBlur() function (if possible). Tried using the keyup function, but this will keep adding numbers to the array where only 3 numbers should be available..
This is what I have so far:
$(document).ready(function() {
$('#a').keyup(function() {
var x = $('#a').val();
hs.push(x);
});
$('#b').keyup(function() {
var y = $('#b').val();
hs.push(y);
});
$('#c').keyup(function() {
var z = $('#c').val();
hs.push(z);
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<input id="a" type="text" />
<input id="b" type="text" />
<input id="c" type="text" />
If I enter 1 in a, 2 in b and 3 in c, then change my mind and change c from 3 to 33, I now have 4 numbers in my array (1,2,3,33), whereas I only want 3 (1,2,33)...
I'm guessing the keyup function is not the way to go here, but would like to keep it as dynamical as possible without forcing the user to change focus from any of the inputs to get a result.
Anyone have an idea how to do this, if even possible ?
hs.a = x; hs.b = y; hs.c = z;