I need help simplifying my current situation.
Step 1: I want to increment the variable "count" by 1 every time a specific div is clicked.
Step 2: After updating "count", I want to utilize it in another function. This function involves copying the value from a select element with an id that includes the updated "count" at the end, and pasting it into an input element with a matching id also including the updated "count".
Issue: The updated "count" works correctly within the function where the value is copied from select to input. However, there seems to be a problem in the initial #id selector with bind(). In this case, the "count" remains unchanged at "0", resulting in the incorrect input element being updated by the select element with "0" at the end of its id.
Could someone offer advice on how to resolve this issue with my variable?
$(document).ready(function () {
var count = 0;
$("#clickBtn").on("click", function (event) {
event.preventDefault();
var textBox = document.getElementById("text");
textBox.value = count;
count++;
});
$('#selectElmnt' + count).bind('change click keyup', function () {
$('#inputElmnt' + count).val($(this).val());
});
});