gjt211
gjt211

Reputation: 7

Javascript calling $(document).on('click', when document ready

I need some help please. The function below works well with an 'up' and 'down' button on a html form.

I want to call this function simulating clicking the 'down' button when the page has finished loading. I don't know how to do this in my $(document).ready(function ()).

Searching here and elsewhere has not provided me any help.

Note that not all the code is shown, so please don't point out errors about undeclared vars thanks.

$(document).on('click', '.sig-spinner button', function () {
    var minval = Math.max(<?php echo $qty_sig_all; ?>,5);
    var btn = $(this),
        oldValue = btn.closest('.sig-spinner').find('input').val().trim(),
        newVal = 0;
    if (btn.attr('data-dir') == 'up') {
        newVal = parseInt(oldValue) + 1;
    } else {
        if (oldValue > minval) {
            newVal = parseInt(oldValue) - 1;
        } else {
            newVal = minval;
        }
    }
    btn.closest('.sig-spinner').find('input').val(newVal);
    document.getElementById("sigtot").innerHTML = '$' + newVal + '.00';
    sigval = newVal;
    totval = sigval + smsval;
    document.getElementById("ordertot").innerHTML = '$' + totval + '.00';
    gstval = (totval - (totval / 1.1)).toFixed(2);
    document.getElementById("gsttot").innerHTML = '$' + gstval;
});

Upvotes: 0

Views: 862

Answers (1)

Matthew Lymer
Matthew Lymer

Reputation: 977

$(document).on('click', '.sig-spinner button', function () {
    ...
});

$(document).ready(function(){
    $('.sig-spinner button').trigger("click");
});

Upvotes: 1

Related Questions