0

I'm looking to fire an updateTotals() function whenever input tags are changed on my form (checkboxes, textboxes).

I'm using Telerik MVC NumericTextBoxes/PercentTextBoxes which ultimately render as tags just like my checkboxes.

I've attempted to apply something like this to my page to do so:

$("#SupervisionRequired").change(updateTotals());

This jQuery fires on the initial page load, but doesn't fire when the Checkbox is changed.

Since I'm using some generic MVC Helpers based on my model (EditorFor, TextBoxFor) I cannot directly apply the onChange event onto these controls. My end goal is to have the updateTotals() function called when a Checkbox is checked/unchecked, and when the user clicks outside of an input tag (for the NumericTextBoxes).

What can I do to change my above jQuery, or add to it to make this possible?

2 Answers 2

3

The correct syntax is

$("#SupervisionRequired").change(updateTotals);

(without the () after updateTotals)

Sign up to request clarification or add additional context in comments.

Comments

1

Wrap the updateTotals() function inside a function(){}.

$("#SupervisionRequired").change(function(){
    updateTotals()
});

Currently, you're immediately calling function updateTotals(), and passing the return value as an event listener to the change event.

Instead of adding the change event to $("#SupervisionRequired"), you an use a selector to select all of your input elements inside your form, eg: $("#myFormName input").change(function(){updateTotals();}).

1 Comment

Thanks, that worked perfectly. I'm glad I posted this right away before tinkering too overly long with syntax!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.