I want to add parameters to the actual url depending on the selected values. The values will be set with a click function and should work independently from each other.
I've set global variables to store the click function values, but they don't get stored. How can I store the values correctely to work with them in my "URLSearchParams" string?
This is the Fiddle.
var btn0;
var btn1;
$('.btn0').click(function () {
if ($(this).attr('data-selected') === 'true') {
$(this).attr('data-selected', 'false');
$(this).removeClass('selected');
} else {
$(this).closest('tr').find('.btn0').not(this)
.removeClass('selected').attr('data-selected', 'false');
$(this).attr('data-selected', 'true');
$(this).addClass('selected');
var btn0 = $(this).data("value");
}
});
$('.btn1').click(function () {
if ($(this).attr('data-selected') === 'true') {
$(this).attr('data-selected', 'false');
$(this).removeClass('selected');
} else {
$(this).closest('tr').find('.btn1').not(this)
.removeClass('selected').attr('data-selected', 'false');
$(this).attr('data-selected', 'true');
$(this).addClass('selected');
var btn1 = $(this).data("value");
}
});
const params = new URLSearchParams({
var0: btn0,
var1: btn1
});
console.log(params.toString());