tags:

views:

43

answers:

1

Can the same "disable" be used to turn off a function using a checkbox for example? Any out there?

A: 

If I've understood what you're asking for, you could assign and remove a click handler for a function, or something along the lines:

<script type="text/javascript">

    function toggleStatus() {
        if ($('#toggle').is(':checked')) {
            $('#alert').click(function() {
                hello();
            });

            $("#toggleLabel").text("on");

        } else {
            $("#toggleLabel").text("off");
            $('#alert').unbind('click');
        }   
    }

    function hello() {
        alert('hello');
    }

</script>

<form id="toggleForm">
    <label id="toggleLabel" for="toggle">off</label>
    <input type="checkbox" id="toggle" name="toggle" onchange="toggleStatus()" />
</form>

<a id="alert" href="#">Function</a>

--

Update:

Hmm, not sure if this is ideal, but this should mimic what you're looking for:

<script type="text/javascript">

    function toggleStatus() {
        if ($('#toggle').is(':checked')) {
            $("#toggleLabel").text("on");
            $("#alert").tipTip();
            $("#tiptip_holder").css('display', '');
        } else {
            $("#tiptip_holder").css('display', 'none !important');
            $("#toggleLabel").text("off");
        }   
    }

</script>

<form id="toggleForm">
    <label id="toggleLabel" for="toggle">off</label>
    <input type="checkbox" id="toggle" name="toggle" onchange="toggleStatus()" />
</form>

<a id="alert" href="#" title="This is a tooltip">Tooltip</a>

I tried looking into unbinding etc, but nothing seemed to work.

waffl
Will this actually turn off a separate function?
Erik
The function I'm trying to turn off is: (function($){ $.fn.tipTip = function(options) { var defaults = { activation: "hover", keepAlive: false, maxWidth: "200px", edgeOffset: 3, defaultPosition: "bottom", delay: 400, fadeIn: 200, fadeOut: 200, attribute: "title", content: false, // HTML or String to fill TipTIp with enter: function(){}, exit: function(){} };
Erik