D
D
Damir Nurgaliev2015-05-25 19:21:06
JavaScript
Damir Nurgaliev, 2015-05-25 19:21:06

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'

)

And the view, where the checkbox itself is.
<%= check_box_tag 'id1' %>
When the checkbox is clicked, the contents of the calendar should change, but there is an error in something. There are no errors in the dev console. What could be the problem?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Viktor Vsk, 2015-05-25
@viktorvsk

Use console.logto 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 question

Ask a Question

731 491 924 answers to any question