I have 3 arrays of same length. I'd like to subtract the values in the first two arrays,without clicking a button, and if the answer is negative, i get the index of that array number, and display a hidden input field(in html) from the 3rd array, whose array index corresponds to the array index of the negative number.
For example:
//assuming this is the first array
array('10','2','3','4','5');
//and assuming this is the second array
array('9','1','4','3','7');
i'd like to subtract the values of the second from the first array, such that i have results, for example:
array('1','1','-1','1','-2');
the above results determines which input fields(from the 3rd array) are to be displayed. For example the input fields to be displayed are those whose array indexes are 2 and 4
here's my code for the 3rd array of input fields:
<?php while($roww = mysql_fetch_array($result)) { ?>
<input type='text' name="reason[]" class="explanation">
<?php } ?>
is there any way i can make the above possible?
So far, this what i've tried, though i haven't applied arrays..just a slight update on a sample i found on the internet...
<html>
<head>
<script src="jquery.min.js"></script>
<script>
$(document).ready(function(){
$(".explanation").hide();
var input1_ = document.getElementById('num1');
var input_ = document.getElementById('num2');
function sub(){
var answer = (parseInt(input1_.value) - parseInt(input2_.value));
if(answer < 0){
$(".explanation").show();
}else $(".explanation").hide();
}
document.getElementById('num1').onkeyup = function () {
sub();
};
document.getElementById('num2').onkeyup = function () {
sub();
};
});
</script>
</head>
<body>
<input type='number' id='num1' value="0">
<input type='number' id='num2' value="0">
<input type='text' class='explanation' value="0">
</body>
</html>