Javascript newbie question
I’m fetching user input from text and use that value to send to the controller for further process. On page init everything is fine, now I want to bind OK button to send users value to my page init script (I’m trying to avoid copying script). Here’s the code
@Html.ActionLink("OK", "Ajax", null, new { @class = "button", @id ="myDate" })
on page init
$(document).ready(function dataTable() {
$('#dataTable').dataTable({
"bServerSide": true,
"fnServerParams": function (aoData) {
var date = $('input[name="myDate"]').val();
aoData.push({ "name": "Date", "value": date });
});
});
on user input and clicking the button I should take that input and sent to the above script to process
$('#myDate').click(function () {
var date = $('input[name="myDate"]').val();
// ????
// Should I change first function to receive parameter as argument
});
One way is to factor out the code to get the date outside the datatable init
Then in your datatable init
and the same in your click event
You should end up with this