0

The below query works great when it comes to checking radio buttons and having the "result value" display.

How do I have the "result value" display on page load since the radio buttons already have checked inputs?

jQuery(document).ready(function ($) {
    $('input[name*="fed"], input[name*="stake"]').change(function () {
        var $this = $(this),
        $wrap = $this.closest('.js-weight-calc-wrap'),
        fedVal = $wrap.find('input[name*="fed"]:checked').val(),
        stakeVal = $wrap.find('input[name*="stake"]:checked').val(),
        result = fedVal === 'Very High' ? '3'
             : fedVal === 'High' && stakeVal === 'Very High' ? '3'
             : fedVal === 'Low to Moderate' && stakeVal !== 'Very High' ? '1'
             : '2';
        $wrap.find('.js-result').text(result)
    });
});

1 Answer 1

1

The simplest solution would be to just trigger the change event on the input manually on dom ready.

$('input[name*="fed"], input[name*="stake"]').trigger('change');
Sign up to request clarification or add additional context in comments.

1 Comment

No, just add my line after your change function.

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.