Your question should be specific to WordPress. Generic PHP/JS/SQL/HTML/CSS questions might be better asked at Stack Overflow or another appropriate Stack Exchange network site. Third-party plugins and themes are off-topic for this site; they are better asked about at their developers' support routes.
Closed 6 years ago.
Improve this questionOn WordPress I'm switching between categories of posts with a dropdown, and have a "load more" button that loads more posts into the selected category. Each time the button is pressed, a variable is updated, so WordPress knows whether to load the 2nd, 3rd, 4th tranche of posts in that category.
The counter ought to reset when the dropdown is changed though - and I can't figure out how to do it.
To simplify, if you have:
<select id="selection">
<option value="foo"></option>
<option value="bar"></option>
</select>
<button id="button"></button>
I want to to get a string of alerts - one per button click - saying "foo1", "foo2" // "bar1", "bar2" // "foo1", "foo2", "foo3".
My code doesn't quite work though - after a while changing the dropdown I get multiple alerts for a single button click.
$(document).ready(function(){
$("#selection").on('change', function(){
myval = $("#selection").val();
count = 0;
$("button").on('click', function(){
count++;
alert(myval + count);
})
})
})
How can I completely wipeout my count value when the selector changes?
Closed. This question is off-topic. It is not currently accepting answers.Your question should be specific to WordPress. Generic PHP/JS/SQL/HTML/CSS questions might be better asked at Stack Overflow or another appropriate Stack Exchange network site. Third-party plugins and themes are off-topic for this site; they are better asked about at their developers' support routes.
Closed 6 years ago.
Improve this questionOn WordPress I'm switching between categories of posts with a dropdown, and have a "load more" button that loads more posts into the selected category. Each time the button is pressed, a variable is updated, so WordPress knows whether to load the 2nd, 3rd, 4th tranche of posts in that category.
The counter ought to reset when the dropdown is changed though - and I can't figure out how to do it.
To simplify, if you have:
<select id="selection">
<option value="foo"></option>
<option value="bar"></option>
</select>
<button id="button"></button>
I want to to get a string of alerts - one per button click - saying "foo1", "foo2" // "bar1", "bar2" // "foo1", "foo2", "foo3".
My code doesn't quite work though - after a while changing the dropdown I get multiple alerts for a single button click.
$(document).ready(function(){
$("#selection").on('change', function(){
myval = $("#selection").val();
count = 0;
$("button").on('click', function(){
count++;
alert(myval + count);
})
})
})
How can I completely wipeout my count value when the selector changes?
You can do this with each function by creating the array and push the selected value into it.
<select id="selection">
<option value="foo"></option>
<option value="bar"></option>
</select>
var arrayOfValues = new Array();
$("select").each(function(i,obj){
count = 0;
$(obj).change(function() {
$("select").each(function(i,obj){
count++;
arrayOfValues.push($(obj).find(":selected").val()+count);
});
alert(arrayOfValues);
});
});
Hope this will help you and also let me know the result.