Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8876341
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T19:11:30+00:00 2026-06-14T19:11:30+00:00

I am learning javascript, and am trying to adjust the following: $(‘#myform’).change(function() { if

  • 0

I am learning javascript, and am trying to adjust the following:

$('#myform').change(function() {
    if ($('#sv_I4b').attr('checked')||$('#sv_I4c').attr('checked')){
        $('#sv_I5').removeClass('hidden');
    } else {
        $('#sv_I5').addClass('hidden');
    }
});

To be a a function with a name that I can call on different events, such as page load etc.

I don’t yet fully understand each element, but I know that:

    if ($('#sv_I4b').attr('checked')||$('#sv_I4c').attr('checked')){
        $('#sv_I5').removeClass('hidden');
    } else {
        $('#sv_I5').addClass('hidden');
    }

is the core “logic” of the function: if (condition) {then this} else {that}

and more or less understand what is happening there. Which leaves the bounding javascript (is there better terminology than that?):

$('#myform').change(function() {...});

My Questions (are the following true etc):

  • The dollar I think denotes that it is jQuery
  • The id my form obviously
    pertains the script to events within that form (namespace?)
  • .change seems to be, a trigger that listens to … any change taking place
    within #myform? so every time a change happens within #myform this
    runs? That seems inefficient
  • function() I don’t yet understand what
    an anonymous or empty function does, just defines what is contained
    in {} as a function?

My goal: to be able to have something like

function myfunction()
{
if ($('#sv_I4b').attr('checked')||$('#sv_I4c').attr('checked')){
        $('#sv_I5').removeClass('hidden');
    } else {
        $('#sv_I5').addClass('hidden');
    }
}

and then

$(function() {myfunction});

so I can call that function on page load, but I don’t wan’t to loose the functionality the .change syntax is providing me (that it changes as the user interacts with the elements on the page also.

Apologies for the general and cumbersome levels of ignorance

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T19:11:31+00:00Added an answer on June 14, 2026 at 7:11 pm

    You guessed how to define the function correctly — that is,

    function myfunction()
    {
    if ($('#sv_I4b').attr('checked')||$('#sv_I4c').attr('checked')){
            $('#sv_I5').removeClass('hidden');
        } else {
            $('#sv_I5').addClass('hidden');
        }
    }
    

    works just fine. However, this:

    $(function() {myfunction});
    

    Should be written as:

    $(myfunction);  // Run on page load.
    $('#myform').change(myfunction);  // ...and also run it when the form changes.
    

    However, that second line won’t actually work until the page has loaded unless the form exists at the time the script runs, so you may want to change it to this:

    $(function() {  // On page load, run this anonymous function:
        myfunction();  // Run the function now (where now, at this point, is page load).
        $('#myform').change(myfunction);  // ...as well as when the form changes.
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm learning javascript and I'm trying to figure out why my below function doesn't
I'm a JavaScript novice trying to build a basic share button as a learning
I'm in the process of learning HTML5 (and OO Javascript) and am trying to
I'm learning Python, Django, Javascript and jQuery by trying to build a simple shopping
I'm learning javascript. I know we can pass a function to other functions after
I am just learning Javascript and I am trying to create a script that
As an exercise in learning RegEx in JavaScript, I've been trying to select an
I'm learning Javascript, and here's what I'm trying to do... <body> <select name=selTitle id=titles>
I'm just learning javascript so please bear with me here. I'm trying to initiate
I'm learning XSLT and Javascript and I'm trying to load some XSLT generated XHTML

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.