I want to get two values from a form and pass it to the controller while I press a button.
The code I have so far is:
<div id="date">
<script src="//code.jquery.com/jquery-1.10.2.js"></script>
<script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
<p>@Resources.Resources.Date: <input type="text" id="datepicker"></p>
<script name="select_date" id="select_date">
$(function getInfo() {
intDate = Date;
var userName = $('#search_employee').val();
$("#datepicker").datepicker({
//defaultDate: "+1w",
changeMonth: true,
changeYear: true,
numberOfMonths: 1,
minDate: "01/01/2008"
});
$("button.action").click(function () {
//console.log(select_date);
var date = $('#datepicker').val().toString();
$.ajax('EmployeeDate', {
data: {
strUserName: userName,
strDate: date
},
success: function (data, textStatus, jqXHR) {
//this will happen on success of request
$('#DataUser').html(data);
},
error: function () {
console.log("error handler when ajax request fails... ");
},
});
});
});
</script>
<button onclick="getInfo()" id="userButton">@Resources.Resources.ButtonFind</button>
<br>
`
When I execute the code I get this error:
0x800a1391 - JavaScript runtime error: 'getInfo' is undefined
Whats wrond in the code?
Thanks!
EDIT
$(function () {
intDate = Date;
var userName = $('#search_employee').val();
$("#datepicker").datepicker({
//defaultDate: "+1w",
changeMonth: true,
changeYear: true,
numberOfMonths: 1,
minDate: "01/01/2008"
});
$("button.action").click(function () {
//console.log(select_date);
var date = $('#datepicker').val().toString();
$.ajax('EmployeeDate', {
data: {
strUserName: userName,
strDate: date
},
success: function (data, textStatus, jqXHR) {
//this will happen on success of request
$('#DataUser').html(data);
},
error: function () {
console.log("error handler when ajax request fails... ");
},
});
});
});
</script>
<button class="action" type="button">@Resources.Resources.ButtonFind</button>
<br>
when I press the button nothing happens.. thanks
function getInfo() {(but having a.click()handler inside the function does not make sense - and you don't appear to have a button withclass="action" anyway). What is it that you want to actulayy do when you click on the button withid="userButton"`?$(function getInfo() {to$(function() {and change$("button.action").click(function () {to$('#userButton').click(function() {and removeonclick="getInfo()"from the button's html