Answer the question
In order to leave comments, you need to log in
How to pass checkbox value from view to script?
There is a coffeescript
calEvents = '/userindex.json'
$(document).on 'change', '#id1', ->
if @checked
calEvents = '/events.json'
return
else
calEvents = '/userindex.json'
return
$(document).ready ->
$("#calendar").fullCalendar(
events: calEvents
eventColor: '#378006'
eventBackgroundColor: 'red'
)
<%= check_box_tag 'id1' %>
Answer the question
In order to leave comments, you need to log in
Use console.log
to see where the code is running and where it's not.
In the browser console, first of all, see if the request is being sent, then - what comes in the response.
But here most likely you do not understand how your plugin works.
On page load, the plugin is activated with the calEvents variable. After, when you click on the checkbox, the variable changes. But whether the plugin will respond to this (99% that it won't) is a matter of how the plugin works.
You need to reinitialize your calendar or whatever you're doing. Now when you click on the checkbox, you simply change the global variable from one string value to another.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question