I want to pass the value which I am taking from the javascript to a controller. But I don't use any function. I just want to access the value which I get from the view in the controller. I have the following view.
<select id="selected_year" name="selected_year" data-live-search="true" style="margin-left: 27px;" >
<option value="2015">2015</option>
<option value="2016">2016</option>
<option value="2017">2017</option>
<option value="2018">2018</option>
<option value="2019">2019</option>
<option value="2020">2020</option>
<option value="2021">2021</option>
<option value="2022">2022</option>
<option value="2023">2023</option>
<option value="2024">2024</option>
</select>
I am getting the value of the drop down using the following javascript.
<script type="text/javascript">
$("#selected_year").live('change', function() {
var selected_year = $(this).attr("value");
alert(selected_year);
window.location.reload();
});
</script>
I want to just pass the value I am getting from the above javascript into a controller. Is it possible to do it?
You would accomplish that either by sending a POST request that would be dispatched to a controller action (synchronously or asynchronously, depending on your need) or passing it as a query string in the url and then checking for it's presence in your controller.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With