Good Morning,
I am new to coding and learning laravel for home project. I am trying to get data from database as per dropdown selection. The code for dropdown item is as below
<div class="dropdown">
<button class="btn p-0" type="button" data-bs-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
<i class="bx bx-dots-vertical-rounded"></i>
</button>
<div id="milkstatementdropdown" name="milkstatementdropdown"class="dropdown-menu dropdown-menu- end" aria-labelledby="milkstatementdropdown">
<li><a class="dropdown-item" href="javascript:void(0);">Yesterday</a></li>
<li><a class="dropdown-item" href="javascript:void(0);">Last 7 Days</a></li>
<li><a class="dropdown-item" href="javascript:void(0);">Last Month</a></li>
<li><a class="dropdown-item" href="javascript:void(0);">Last 3 Month</a></li>
<li><a class="dropdown-item" href="javascript:void(0);">Last 6 Month</a></li>
</div>
</div>
`
After selection of drop down item, need to get value and then pass the same to controller using AJAX.
below is the script for getting the selection value and process ajax.
`
$("#milkstatementdropdown").change(function(){
var duration = $(this).val();
alert(course);
// ajax call
});
`
i am not able to get the Alert..
Did i miss something and make mistake in code…
Thanks in Advance.
3
Answers
try this
Try this one // You can use Anything
You have to use onClick beacuase your dropdown is not an Select Tag:-
And then in your Javascript part you have make get_data function to hanle onClick event.