Hey guys...
I'm making a program where I want to store some values in an array. The values are taken from a couple of input fields. I use the input fields randomly (not in order). But I want to store these values in order in the array. I thought I could do this by checking if a certain input field is filled. And to make sure the value from that field did not get added to the array every time I hit the event-button I changed the background color of the input field to check if I already had added that value to the array.
<script>
var x = 0;
var array = [];
$("button").on("click", function() {
console.log("Before IF: " + $("input:eq(0)").val() + " - " + $("input:eq(0)").css("background-color"));
if($("input:eq(0)").val() != "" && $("input:eq(0)").css("background-color") != "rgb(255,255,0)") {
array[x] = $("input:eq(0)").val();
x++;
$("input:eq(0)").css("background-color","rgb(255,255,0)");
} else if($("input:eq(1)").val() != "" && $("input:eq(1)").css("background-color") != "rgb(255,255,0)") {
array[x] = $("input:eq(1)").val();
x++;
$("input:eq(1)").css("background-color","rgb(255,255,0)");
} else if($("input:eq(2)").val() != "" && $("input:eq(2)").css("background-color") != "rgb(255,255,0)") {
array[x] = $("input:eq(2)").val();
x++;
$("input:eq(2)").css("background-color","rgb(255,255,0)");
}
console.log("After IF: " + $("input:eq(0)").val() + " - " + $("input:eq(0)").css("background-color"));
console.log(array);
console.log("---------------------------------");
});
</script>