Question

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

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top