Reputation: 2464
I tried a jquery function using jQuery and it's not working
It's pretty weird. I put some alerts in the js file, but when I click on the button (with id="gettotalnutrients"), none of the alerts from the js file happen.
this is where I grab the data for the js file (and display the data):
<div id="feedback"></div>
<br />
<form id="form_date_nutrient_getter" action="account-overview.php" method="POST">
Select a start date: <input id="datestart" type="text" name="beginday_calendar"><br />
Select a end date: <input id="dateend" type="text" name="endday_calendar"><br />
<input type="button" id="gettotalnutrients" value="Get the total nutrients" ><br /><br /><br /><br /><br /><br /><br />
</form>
</div>
js file:
$('#gettotalnutrients').click(function(){
alert('test');
var datestart = $('#datestart').val();
alert(datestart);
var dateend = $('#dateend').val();
alert(dateend);
$.post('getTotalNutrients.php',(beginday_calendar: datestart, endday_calendar: dateend), function(data){
$('#feedback').text(data);
});
});
Upvotes: 1
Views: 111
Reputation: 218702
Did you try chnaging the brackets to {
$(function(){
$('#gettotalnutrients').click(function(){
//remaining code
$.post('getTotalNutrients.php',{ beginday_calendar: datestart, endday_calendar: dateend}, function(data){
$('#feedback').text(data);
});
});
});
Upvotes: 1
Reputation: 2224
wrap your click() function in $(document).ready() or something like that:
$(document).ready(function() {
$('#gettotalnutrients').click(function(){
// the rest of your code goes here
});
});
Also, are you seeing any errors in the js console?
Upvotes: 3