Reputation: 1
How can I get the value of a td, when I click on that spepcific td and save the value in an sql database. The table is build in this way:
$calendar.= '<td class="calendar-day" value="'.$current_day.'">';
$calendar.= '<p>Nurse: '.$nurse_number.' </p><p>Senior: '.$senior_number.' </p>';
$calendar.= '</td>';
Thank you very much!
Upvotes: 0
Views: 295
Reputation: 3754
Try This :
$('td').click(function(){
$.ajax({
type: "POST",
url: "some.php",
data: { value:$(this).attr('value') }
})
.done(function( msg ) {
alert( "Data Saved: " + msg );
});
});
Get value on some.php and save it to database.
M.
Upvotes: 0
Reputation: 159
You have to use ajax. here is a sample code:
var xmlhttp;
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("myDiv").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","ajax_info.txt",true);
xmlhttp.send();
or if you use jquery this is the syntax:
$.ajax({
type: "POST",
url: "some.php",
data: { name: "John", location: "Boston" }
})
.done(function( msg ) {
alert( "Data Saved: " + msg );
});
for more info read: ajax
Upvotes: 1