none
How to call two javascript functions in one button click RRS feed

All replies

  • Hello,

    The following example there is a web page and a backing .js file.

    In the web page there is a input of type button named btnNotifications

    <div class="row">
    	<div class="well">
    		<div class="col text-center">
    			<button type="button" class="btn btn-primary" id="btnNotifications">
    				Claims Notifications <span class="badge badge-light" id="lblIncrement">0</span>
    			</button>
    		</div>
    	</div>
    </div>
    

    An include in the header

    <script src="Scripts/Local/index.js"></script>

    An abbreviated javascript file where the input above we subscribe to the click event in which you can call functions that are visible to this javascript file or perhaps create a new instance of another javascript class.

    $(document).ready(function () {
        $('#btnGetNotificationCount').click(function (event) {
    		// call as many functions as you wish
        });  
    });

    In regards to say calling a method in another class, add that class to the includes for the web page then call it. Here is an example of a class in the event you are unsure what I'm talking about.

    var $commonUtils = $commonUtils || {};
    $commonUtils = function () {
    
        var stringStripToInt = function (sender) {
            return sender.replace(/\D/g, '');
        };
    
        var stringStripToDecimal = function (sender) {
            return sender.replace(/[^\d.-]/g, '');
        };
    
        var isValidWithDashesSSN = function (sender) {
    
            var ssnPattern = /^[0-9]{3}\-?[0-9]{2}\-?[0-9]{4}$/;
            return ssnPattern.test(sender);
        };
        return {
            isValidWithDashesSSN: isValidWithDashesSSN,
            stringStripToInt: stringStripToInt,
            stringStripToDecimal: stringStripToDecimal
        };
    }();


    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange

    Thursday, July 4, 2019 11:01 AM
    Moderator
  • Thanks for your help.
    Thursday, July 4, 2019 11:27 AM
  • Hi

    Is your problem solved? If so, please post "Mark as answer" to the appropriate answer. So that it will help other members to find the solution quickly if they face the similar issue.

    Best Regards,

    Jack


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, July 11, 2019 5:35 AM
    Moderator