SlimJim
SlimJim

Reputation: 377

jQuery not working from onClick event

For some reason, my jQuery seems not to be working. I have a Javascript function -- TogAddCancel() -- called from the onClick attribute of an input "btnAddCncl," and the function is designed to toggle the value of the button. It works fine without jQuery, but doesn't execute at all with jQuery. Any thoughts?

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>

Without jQuery:

function TogAddCancel() {

    var x = document.getElementById("btnAddCncl").value;
    if (x=="Add") {
        document.getElementById("btnAddCncl").value = "Cancel";
    } else {
        document.getElementById("btnAddCncl").value = "Add";
    }

}

With jQuery

function TogAddCancel() {

    var x = $('#btnAddCncl').val();
    if (x=="Add") {
        $('#btnAddCncl').val("Cancel");
    } else {
        $('#btnAddCncl').val("Add");      
    }
}

TogAddCancel() is called from:

<cfinput type="button" id="btnAddCncl" name="btnAddCncl" onClick="TogAddCancel()">

Upvotes: 0

Views: 644

Answers (2)

SlimJim
SlimJim

Reputation: 377

OK. Figured it out! It was as simple as changing the "http:" in the src="http:// . . . " to "https:// . . . "

Upvotes: 1

Soatl
Soatl

Reputation: 10582

Your script tag is incorrect. Try:

   <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>

Edit

If your typos are cleaned up and it still doesn't work, you can also try using click() with jQuery:

$('#btnAddCncl').click(function() {
    var x = $('#btnAddCncl').val();
    if (x=="Add") {
        $('#btnAddCncl').val("Cancel");
    } else {
        $('#btnAddCncl').val("Add");      
    }
});

No need for an onClick.

Upvotes: 3

Related Questions