I have the following, which I would like to run for the first time when the page loads. Then I would like it to run on keyup as user makes changes. The function I would like to run is very large (stripped down for posting on here) so I don't want to duplicate the function. Is there a way to call the function onload and then reuse it on keyup? Thank you
$(document).ready(function() {
// this calculates the sum for some text nodes
$("td, input").keyup(
function (){
var col_1revenue = $(".Col1Receipts, .Col1Receipts input").sum();
} // function
); // keyup
}); // document ready
An easy way is to create a function and then call it from both:
keyupfunction()
is called the first time the page load completes and when the keyup event gets fired... that is the whole purpose of using a function in a programming language.
$(document).ready(function() {
keyupfunction(); //first call
// this calculates the sum for some text nodes
$("td, input").keyup(keyupfunction); // keyup
}); // document ready
common function
function keyupfunction(){
var col_1revenue = $(".Col1Receipts, .Col1Receipts input").sum();
} // function
Try this
$(document).ready(function() {
XX();
// this calculates the sum for some text nodes
$("td, input").keyup(XX); // keyup
function XX() {
var col_1revenue = $(".Col1Receipts, .Col1Receiptsinput").sum();
} // function
}); // document ready
You could trigger the event once on load.
$("td, input").keyup(
function (){
var col_1revenue = $(".Col1Receipts, .Col1Receipts input").sum();
}
).keyup();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With