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 4566698
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T18:49:32+00:00 2026-05-21T18:49:32+00:00

I have an application that uses Yui 2.0 and some custom JS. I did

  • 0

I have an application that uses Yui 2.0 and some custom JS. I did not write it originally so I am not really familiar with the Yui JS tools. For this problem I will look at three radio buttons and one text input.

The behavior right now is that when you select radio button s3 you enable text input toEnable.

What I would like to see is that when you select radio button S2 or S3 toEnable is enabled. However using the following example what happens is that once you try and use the NCRS_bind_to_radio method on S2, S3 loses the ability to effect the toEnable input all together.

Anyone have any idea how I can get this input enabled/disabled with both radio buttons?

<ul>
  <li><label><input value="MET" type="radio" name="selector" id="s1"> 1</label></li>
  <li><label><input value="MET" type="radio" name="selector" id="s2"> 2</label></li>
  <li><label><input value="MET" type="radio" name="selector" id="s3"> 3</label></li>
<ul>

<input id="change" type="text" name="toEnable">

//S2 is the new addition here, bind for s3 has been around and works by itself, not with s2
NCRS_bind_to_radio('toEnable', 's2', true, true)
NCRS_bind_to_radio('toEnable', 's3', true, true)


function NCRS_bind_to_checkbox(input, checkbox, required, autofocus){ 
    // Bind an input to a checkbox. 
    // i.e., the input is disabled until the checkbox is checked
    // If "required", then "validate-required" is added/removed as needed. 
    // If "autofocus", then when the checkbox is checked, this field
    // automatically gets focus. 
    if (typeof checkbox == "string") {
        checkbox=document.getElementById(checkbox);
    }
    if (typeof input == "string") {
        input = document.getElementById(input);
    }

    YAHOO.util.Dom.removeClass(input, 'validate-required');
    if (required) { 
        YAHOO.util.Event.addListener(input, "blur", 
                NCRS_forms_passive_check_text, input, true)
    }

    input.disabled = !checkbox.checked;

    // Set initial state of "validate-required"
    if (checkbox.checked && required) { 
        YAHOO.util.Dom.addClass(input, 'validate-required');
    }

    // Add a "click" listener to the checkbox/radio
    YAHOO.util.Event.addListener(checkbox, "click", function() { 
        if (checkbox.checked) { 
            input.disabled = false;
            if (autofocus) { 
                input.focus();
            }
            if (required) { 
                YAHOO.util.Dom.addClass(input, 'validate-required');
            }
        } else { 
            NCRS_forms_set_error(input, true)
            YAHOO.util.Dom.removeClass(input, 'validate-required');
            input.disabled = true;
        }
    });

    // If parent is a "radio" input, also add listeners to sibling radios. 
    if (checkbox.type == 'radio') {
        var item;
        for (var i=0; i < checkbox.form[checkbox.name].length; i++) {
            item = checkbox.form[checkbox.name][i]
            if (item != checkbox) {
                // Add a "click" listener to the checkbox/radio
                YAHOO.util.Event.addListener(item, "click", function() { 
                    if (!checkbox.checked) { 
                        NCRS_forms_set_error(input, true)
                        YAHOO.util.Dom.removeClass(input, 'validate-required');
                        input.disabled = true;
                    }
                })
            }
        }
    }

    // Add a "click" listener to the dependent input.
    // This was intended to re-enabled a disabled input,
    // but doesn't work?
    YAHOO.util.Event.addListener(input, "click", function() {
        if (!checkbox.checked) { 
            checkbox.click();
            input.focus();                
        }
    });
}

NCRS_bind_to_radio = NCRS_bind_to_checkbox
  • 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-05-21T18:49:33+00:00Added an answer on May 21, 2026 at 6:49 pm

    The problem is that when one radio button is selected the others are deselected. I believe that when you select S3 the input is enabled briefly, then S2’s deselect disables the input.

    I would modify the method to take an array of inputs, and change this bit of code:

    if (!checkbox.checked)
    { 
      NCRS_forms_set_error(input, true)
      YAHOO.util.Dom.removeClass(input, 'validate-required');
      input.disabled = true;
    }
    

    to something like:

    var state = true;
    for (radio in radioArray)
    {
      state = state && !radio.checked;
    }
    
    if (state)
    { 
      NCRS_forms_set_error(input, true)
      YAHOO.util.Dom.removeClass(input, 'validate-required');
      input.disabled = true;
    }
    

    I’ve worked with YUI a bit and let me offer you a tip to simplify your code. Instead of doing this:

    if (typeof checkbox == "string")
    {
      checkbox=document.getElementById(checkbox);
    }
    if (typeof input == "string")
    {
      input = document.getElementById(input);
    }
    

    you can take advantage of YUI’s DOM utilities.

    var Dom = YAHOO.util.Dom;
    
    checkbox = Dom.get(checkbox);
    input = Dom.get(input);
    

    YUI will check whether it’s a string or not under the hood and always give you a reference to the element, even if you pass an element into get().

    Paul

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this application that uses custom methods to register and loggin users using
I have client application that uses WCF service to insert some data to backend
I have an application that uses simple sockets to pass some characters between two
I have an application that uses the bluetooth to receive some data (bytes) from
I have an application that uses WCF for all DataAccess. It returns some business
I have an application that uses pictures, audio and some text from .txt... The
I have an application that uses various script files. These files are not used
I have an application that uses NHibernate as its ORM and sometimes it experiences
I have an application that uses the accelerometer. Sometimes, the application will launch without
I have an application that uses window.open() to generate dynamic popups. Unfortunately, I've had

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.