I have try to stop refresh page on click on select option but when I stop refresh page then data can not get.
here code
echo "<form name='frmtopdevotees' method='post' action='topuser_load.php'>
<h4>select month <select id='seldrp' name='themonth' OnChange ='document.frmtopdevotees.submit()'>
$optionsmonths
</select>
<select name='topdevotees' id='seldrp' OnChange ='document.frmtopdevotees.submit()'>
<option value=10 $M10>Top 10</option>
<option value=20 $M20>Top 20</option>
<option value=50 $M50>Top 50</option>
<option value=100 $M100>Top 100</option>
</select> </h4>
</form>";
?>
<script>
$('frmtopdevotees').submit(function (e) {
e.preventDefault();
return false;
});
$('themonth').onchange(function () {
$.ajax({
var value = $('themonth').val();
type: 'post',
data: {
topdevotees: topdevotees,
themonth: themonth
},
url: "topuser_load.php?topdevotees=" + topdevotees + "&themonth=" + themonth,
success: function (response) {
$('themonth').append(response);
}
});
});
</script>
when I remove Onchange = 'document.frmtopdevotees.submit()' then page stop to refresh but not data change.
From your code what I can understand is you want to trigger a server call without refreshing the page (AJAX) whenever your any one the select option changes.
There are errors in the code posted. Following is my observation -
There can be only one ID in entire page. You have used 'seldrp' in couple of places.
If you want the AJAX functionality, you should avoid calling submit() function of the form.
The AJAX syntax is wrong which should be as follows -
$.ajax({
url : "topuser_load.php?topdevotees=" + topdevotees + "&themonth=" + themonth,
method: "post",
data: {
topdevotees: topdevotees,
themonth: themonth
}, // can even put this in variable and JSON stringify it
success: function (response) {
$('themonth').append(response);
}
});
Now coming to the solution part of it: I would do this as follows - 1. Will just listen on the select change in JQUERY 2. Once a select change is triggered, AJAX call is made and which returns the response. The modified code is -
<script>
$('select').on('change', function (e) {
var month = $('#seldrp1').val();
var topdevotee = $('#seldrp2').val();
// call ajax here -
$.ajax({
url: "topuser_load.php?topdevotees=" + topdevotee + "&themonth=" + month,
method: "post",
data : JSON.stringify({
topdevotees: topdevotee,
themonth: month
}),
success : function(response){
$('themonth').append(response);
},
error : function(err){
// handle error here
}
});
});
</script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>
echo "<form name='frmtopdevotees'>
<h4>select month <select id='seldrp1' name='themonth'>
$optionsmonths
</select>
<select name='topdevotees' id='seldrp2'>
<option value=10 $M10>Top 10</option>
<option value=20 $M20>Top 20</option>
<option value=50 $M50>Top 50</option>
<option value=100 $M100>Top 100</option>
</select> </h4>
</form>";
?>
This regex matches "so" when it's preceded by a comma and a space: (,\s)(so) I want to do the opposite now. I want to tell the regex: don't match "so" if it's preceded by a comma and a space. I ...
This regex matches "so" when it's preceded by a comma and a space: (,\s)(so) I want to do the opposite now. I want to tell the regex: don't match "so" if it's preceded by a comma and a space. I ...
I tried to do this calculation with Node.js. let x = 841251657 console.log((x*x)-x) I got: 707704349563994000 printed. When I use julia I get 707704350405245649 for the same calculation. And I got ...
I tried to do this calculation with Node.js. let x = 841251657 console.log((x*x)-x) I got: 707704349563994000 printed. When I use julia I get 707704350405245649 for the same calculation. And I got ...
In many places I'm setting modified by, created by etc: const test = this.state.isValueEdited ? { modifiedById: getLoggedInUser().userId, } : { // TODO }; How could I check if getLoggedInUser has ...
In many places I'm setting modified by, created by etc: const test = this.state.isValueEdited ? { modifiedById: getLoggedInUser().userId, } : { // TODO }; How could I check if getLoggedInUser has ...
I have an Array with Objects, there some of them has same "Subarrays" but with different labels. I need to summarize those based on equality. Comparing two different arrays is easy so far, but I am ...
I have an Array with Objects, there some of them has same "Subarrays" but with different labels. I need to summarize those based on equality. Comparing two different arrays is easy so far, but I am ...