Home > Net >  Why is checkbox onclick function not working?
Why is checkbox onclick function not working?

Time:12-22

Im building a flask app, but I cant figure out how to get the onclick event for the checkboxes to work. The function toggleAlarm should trigger a request but I'm not receiving anything. The click event for the button is working fine tough.

'''

{% for alarm in alarms %} {{ alarm.time }} {{alarm.days}}

  <button type="button" id="alarm-delete"  onClick=deleteAlarm({{ alarm.id | safe }})>
    <span aria-hidden="true">&times;</span>
  </button>
  <label>
    {% if alarm.state == 1 %}
    <input type="checkbox" id="{{ alarm.id }}" onClick=toggleAlarm({{ alarm.id | safe }}) checked>  
    {% else %}
    <input type="checkbox" id="{{ alarm.id }}" onClick=toggleAlarm({{ alarm.id | safe }})> 
    {% endif %}
  </label>
</li>
{% endfor %}

'''

CodePudding user response:

You're missing quotes for the onclick attribute.

<input type="checkbox" id="{{ alarm.id }}" onClick=toggleAlarm({{ alarm.id | safe }})>

Should be

<input type="checkbox" id="{{ alarm.id }}" onclick="toggleAlarm({{ alarm.id | safe }});">

It's not required but you should also do onclick instead of onClick as that's the proper attribute camelCase name

  • Related