How can I update one field in MySQL table after user clicks on checkbox. I have this:
<div style="float: right"><input type="checkbox" class="tvSync" data-toggle="toggle" data-onstyle="success" onclick="myFunction({{$spot->spotid}})"></div>
and
function myFunction(id)
{
var spotid=spotid;
$.ajax({
type:'post',
url:'updateTvSync',
data:{spotid: spotid},
success:function(msg){
console.log(msg)
}
});
}
I created the route /updateSync and included it in controller:
public function updateTvSync(Request $request)
{
$id = $request->spotid;
TV::where('spotid', $id)->update(['delayed' => 1]);
}
but when I click on checkbox nothing happens. Does this <div> need to be in form or am I missing something here?
$spot->spotidonclick="myFunction(469871)"for example.