Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7974251
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T08:19:13+00:00 2026-06-04T08:19:13+00:00

This is a bit of a long question so please bear with me guys.

  • 0

This is a bit of a long question so please bear with me guys.

I needed to make a form submit automatically when a checkbox was ticked. So far I have the code below and it works perfectly. The form must submit when the check box is either checked or unchecked. There is some PHP that reads a database entry and shows the appropriate status (checked or unchecked) on load.

<form method="post" id="edituser" class="user-forms" action="--some php here--">
    <input class="lesson" value="l101" name="flesson" type="checkbox" />
</form>
<script>
    $('.lesson').change(function() {
        $('.user-forms').submit(); 
    });
</script>

However, when I introduce a fancy checkbox script which turns checkboxes into sliders it no longer works. The checkbox jQuery script is below:

<script src="'.get_bloginfo('stylesheet_directory').'/jquery/checkboxes.js"></script>
<script type="text/javascript" charset="utf-8">
    $(document).ready(function(){
    $("input[type=checkbox]").tzCheckbox({labels:["Enable","Disable"]});
    });
</script>

The contents of the checkboxes.js called to above is as follows:

(function($){
$.fn.tzCheckbox = function(options){

    // Default On / Off labels:

    options = $.extend({
        labels : ['ON','OFF']
    },options);

    return this.each(function(){
        var originalCheckBox = $(this),
            labels = [];

        // Checking for the data-on / data-off HTML5 data attributes:
        if(originalCheckBox.data('on')){
            labels[0] = originalCheckBox.data('on');
            labels[1] = originalCheckBox.data('off');
        }
        else labels = options.labels;

        // Creating the new checkbox markup:
        var checkBox = $('<span>',{
            className   : 'tzCheckBox '+(this.checked?'checked':''),
            html:   '<span class="tzCBContent">'+labels[this.checked?0:1]+
                    '</span><span class="tzCBPart"></span>'
        });

        // Inserting the new checkbox, and hiding the original:
        checkBox.insertAfter(originalCheckBox.hide());

        checkBox.click(function(){
            checkBox.toggleClass('checked');

            var isChecked = checkBox.hasClass('checked');

            // Synchronizing the original checkbox:
            originalCheckBox.attr('checked',isChecked);
            checkBox.find('.tzCBContent').html(labels[isChecked?0:1]);
        });

        // Listening for changes on the original and affecting the new one:
        originalCheckBox.bind('change',function(){
            checkBox.click();
        });
    });
};
})(jQuery);

There is also some CSS that accompanies this script but I am leaving it out as it is not important.

Finally, this is what the jQuery script does to the checkbox:

<input id="on_off_on" class="lesson" value="lesson11-1" name="forexadvanced[]" type="checkbox" style="display: none; ">
<span classname="tzCheckBox checked" class=""><span class="tzCBContent">Disable</span><span class="tzCBPart"></span></span>

When the checkboxes are changed into sliders the .change() function no longer detects the change in the checkboxes status.

How can I make the .change() function work or is their an alternative function I can use?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T08:19:15+00:00Added an answer on June 4, 2026 at 8:19 am

    This plugin changes your checkboxes to span elements and hides the actual checkboxes themselves. Thus, when you click on them, nothing happens. Since span elements don’t have onchange events, you can’t bind change events to these.

    However, span elements do have click events, meaning that you could instead bind a click event to the generated spans, using Firebug or Chrome Debugger to locate the correct element to bind to.

    Your click-handler can then take the same action your change event would normally take if the plugin weren’t being used.

    Here is an example:

    HTML (Source):

    <!-- This is a checkbox BEFORE running the code that transforms the checkboxes 
       into sliders -->
    <li>
        <label for="pelda1">Opció 1:</label>
        <input class="pelda" type="checkbox" id="pelda1" name="pelda1" />
    </li>
    

    HTML (Generated From Chrome Debugger):

    NOTE: This is the generated HTML after running the JavaScript that converts checkboxes to sliders! You must bind your click event AFTER this code is generated.

    <li>
        <label for="pelda1">Option 1:</label>
    
        <!-- The hidden checkbox -->
        <input class="pelda" type="checkbox" id="pelda1" name="pelda1" style="display: none; " />
    
        <!-- the "checked" class on the span gets changed when you toggle the slider 
             if it's there, then it's checked. This is what you're users are actually
             changing. 
        -->
        <span class="tzCheckBox checked">
            <span class="tzCBContent">active</span>
            <span class="tzCBPart"></span>
        </span>
    </li>
    

    JavaScript:

    NOTE: This must be bound AFTER converting the checkboxes to sliders. If you try it before, the HTML won’t yet exist in the DOM!

    $('.tzCheckBox').click(function() {
    
        // alert the value of the hidden checkbox
        alert( $('#pelda1').attr("checked") );
    
        // submit your form here
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This question is a bit long, please bear with me. In REST, i think
This question might be a bit long and specific, but I have been attempting
This question is a bit long due the source code, which I tried to
This is a bit of a long shot as I don't have access to
NOTE: This is a long question. I've explained all the 'basics' at the top
This looks like a long question because of all the context. There are 2
This question seems to come up a bit and I've yet to see a
This is a long question so i apologize if it takes a while to
I know I'm not asking this quite right, either. Please help me better form
Sorry for this long question, it is flagged wiki since I'm asking for something

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.