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 9073327
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T18:23:27+00:00 2026-06-16T18:23:27+00:00

Okay, So I have looked through all the other questions around trigger not working.

  • 0

Okay, So I have looked through all the other questions around trigger not working. I think my question is a bit different from the others I believe.

I have this here listening for clicks on a div:

$(".switch").click(function(){
    var state = ( $(this).children('.b1').is('.btn-success') ? 0 : 1 );
    $(this).attr('data-state', state  );
    $(this).children('.b1').toggleClass('btn-success');
    $(this).children('.b0').toggleClass('btn-danger');
    $(this).trigger('stateChanged', state);
});

Notice at the bottom I try to trigger the event stateChanged, in on document ready I run this function…

function data_depends(){
    var key_name = urlName();
    $(document).find('[data-depends]').each(function(index){
        var depends = $(this).data("depends").split(", ");
        if(depends != null)
            if(depends[1] == "state"){
                if($(depends[0]).data("state") == "0")
                    $(this).show(500);
                else
                    $(this).hide(500);
                var a = this;
                $(depends[0]).bind("stateChanged", 
                            function(x){if(x) $(a).show(500); 
                                        else $(a).hide(500);});
            }
    });
}

notice in that function I have…

$(depends[0]).bind("stateChanged", function(x){if(x) $(a).show(500);
else $(a).hide(500);});

But the function just is never called.

Here’s the html

<div class="control-group">
    <label class="control-label" for="sale">Outcome</label>
    <div class="controls">
        <div id="sale" class="btn-group switch" data-toggle="buttons-radio" data-state="0" data-persist>
            <button type="button" class="btn b1">Sale</button>
            <button type="button" class="btn b0 btn-danger">No Sale</button>
        </div>
    </div>
</div>
<div class="control-group" data-depends="#sale, state">
    <label class="control-label" for="reason">No sale reason</label>
    <div class="controls">
        <input id="reason" type="text" placeholder="No sale reason" data-persist ><br>
    </div>
</div>
  • 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-16T18:23:28+00:00Added an answer on June 16, 2026 at 6:23 pm

    So this here goes back to this question here: https://superuser.com/questions/527761/javascript-being-cached-in-chrome

    Sometime it does it, sometimes it doesn’t.

    So for anyone that wants to use a input field that depends on a switch…..

    PS. Requires jquery and bootstrap.


    javascript
    
    $(".switch").click(function(){
        var state = ( $(this).children('.b1').is('.btn-success') ? 0 : 1 );
        $(this).attr('data-state', state  );
        $(this).children('.b1').toggleClass('btn-success');
        $(this).children('.b0').toggleClass('btn-danger');
        $(this).trigger('stateChanged', state);
        //$("#" + this.id).trigger('stateChanged', state);
    });
    
    function data_depends(){
        var key_name = urlName();
        $(document).find('[data-depends]').each(function(index){
            var depends = $(this).data("depends").split(", ");
            if(depends != null)
                if(depends[1] == "!state"){
                    var a = this;
                    $(depends[0]).bind("stateChanged", function(evt, x){if(!x) {$(a).show(500);}else{ $(a).hide(500);}});
                }else if(depends[1] == "!state"){
                    var a = this;
                    $(depends[0]).bind("stateChanged", function(evt, x){if(x) {$(a).show(500);}else{ $(a).hide(500);}});
                }
    
        });
    }
    
    $(document).ready(function(e) {
        data_depends();
        $(".switch").trigger('stateChanged', 0);
    });
    

    html
    
    <div class="control-group">
        <label class="control-label" for="sale">Outcome</label>
        <div class="controls">
            <div id="sale" class="btn-group switch" data-toggle="buttons-radio" data-state="0" data-persist>
                <button type="button" class="btn b1">Sale</button>
                <button type="button" class="btn b0 btn-danger">No Sale</button>
            </div>
        </div>
    </div>
    <div class="control-group" data-depends="#sale, state">
        <label class="control-label" for="reason">No sale reason</label>
        <div class="controls">
            <input id="reason" type="text" placeholder="No sale reason" data-persist ><br>
        </div>
    </div>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Okay, I have looked hard for this answer, but all the websites, even the
Disclaimer: I have looked through this question and this question but they both got
I have read through all the threads out there that looked as if they
Okay, I've looked around a bit, and I cannot seem to find the answer.
Okay I have updated my code quite a bit. I am getting a new
Okay I have updated my code a little, but I am still not exactly
Okay i have two models: posts and comments. as you can think comments has
My Research: Okay, I have looked at dozens upon dozens of examples for Write-Progress
I've looked around, and I do see previous questions where people ask about Date/Time
Okay, so I've looked at all the threads on StackOverflow, and I couldn't find

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.