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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T04:02:45+00:00 2026-05-31T04:02:45+00:00

I have 4 jquery radio buttons in my form something like this <form:radiobutton path=lcmoption

  • 0

I have 4 jquery radio buttons in my form something like this

<form:radiobutton path="lcmoption" name ="lcmoptions" id ="lock" value="lock" checked="checked"/>
<fmt:message key="lcm.form.options.lock" />&nbsp;

<form:radiobutton path="lcmoption" name ="lcmoptions" id="unlock" value= "unlock"/>
<fmt:message key="lcm.form.options.unlock" /> &nbsp;

<form:radiobutton path="lcmoption" name ="lcmoptions" id="terminate" value="terminate" />
<fmt:message key="lcm.form.options.terminate" /> &nbsp;

<form:radiobutton path="lcmoption" name ="lcmoptions" id="wipe" value="wipe" />
<fmt:message key="lcm.form.options.wipe" /> &nbsp;

<form:radiobutton path="lcmoption" name ="lcmoptions" id="other" value="other" />
<fmt:message key="lcm.form.options.other" /> &nbsp;

onclick of the first four radio buttons I am dynamically loading the select box using an AJAX call. When the user clicks the last option, i.e, other, I need to hide the textbox and show a text area.

I tried using:

$("input:radio[name=lcmoption]").click(function() {
    if(type=="other")
    {
        $([name="reasonsList"]).css("display",none");
        $([name="otherreasonsList"]).css("display", "block");
    }
    else
    {
        // AJAX CALL to load dropdown (for other options)
    }
}

But this did not work. I also tried:

$([name="reasonsList"]).hide();
$([name="otherreasonsList"]).show();

This shows both the dropdown and text area. Can anyone help me on hiding reasonsList div and show otherreasonsList div onclick of a radio button with other value?

  • 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-31T04:02:47+00:00Added an answer on May 31, 2026 at 4:02 am

    There’s all kinds of syntax errors in the code you posted.

    For instance, you need to quote your selector strings as text, and an attribute value in an attribute selector ([name=something]) can be either an unquoted single word or a quoted string.

    In this case, just leave it out:

    $('[name=reasonsList]').show();
    

    Also, instead of $.click(), I would use $.change(), which will detect when the radio value has changed.

    $("input:radio[name=lcmoptions]").change(function(){...});
    

    See notes in comments:

    // First line looks ok, but I would use a .change() handler
    // Also, I just noticed you're:
    //     "input:radio[name=lcmoption]"
    //
    // But shouldn't it be:
    //     "input:radio[name=lcmoptions]"
    //
    // See lcmoptions vs lcmoption (no s on second); it's lcmoptions
    // in your template code. I don't know what path="lcmoption" means,
    // but I think name="lcmoptions" is what you need to use to select.
    $("input:radio[name=lcmoption]").click(function() {
        // What is type? I think you mean this.value or $(this).val()
        // Don't forget to lowercase the comparison, so other matches
        // Other.
        if (this.value.toLowerCase() == "other")
        {
            // The selector needs to be quoted as a string, ie:
            //     '[name="reasonsList"]'
            //
            // Also, jQuery has a shortcut method, $(sel).hide();
            $([name="reasonsList"]).hide();
    
            // The same thing here, you need to quote that string or 
            // alternatively, since it's a single word, leave the quotes
            // out of the selector, ie:
            //     $('[name=otherreasonsList]')
            //
            // Again, jQuery has a shortcut method, $(sel).show();
            $('[name=otherreasonsList]').show();
        }
    // Don't know if you missed this in the example, but you need });
    // to close the $.click() function.
    });
    

    And your second attempt:

    // Same problem as above, you need to quote the string for the
    // selector, ie:
    //     $('[name=reasonsList]')
    //
    // With inner quotes, but here they're unnecessary.
    $('[name="reasonsList"]').hide();
    //
    // Without inner quotes on name value
    $('[name=otherreasonsList]').show();
    

    For what you’re wanting to do, you can:

    $(document).ready(function(){
        // This is called caching, which is a good practice to get
        // get into, as unless you need to requery due to dynamic
        // changes, selecting them only once and reusing will give
        // you better performance.
        var $lcmoptions = $('input:radio[name=lcmoptions]'),
            $textbox = $('[name=textbox]'),
            $textarea = $('[name=textarea]');
    
        $lcmoptions.change(function(){
            // Note I this.value.toLowerCase() the comparison value
            if (this.value.toLowerCase() === 'other') {
                $textbox.hide();
                $textarea.val($textbox.val()).show();
            } else {
                $textarea.hide();
                $textbox.val($textarea.val()).show();
            }
        });
    });
    

    For more information on caching, see:

    Does using $this instead of $(this) provide a performance enhancement?

    This is assuming your client-side markup looks something like:

    <input type="radio" name="lcmoptions" id="unlock" value= "lock"/> Lock &nbsp;
    <input type="radio" name="lcmoptions" id="unlock" value= "unlock"/> Unlock &nbsp;
    <input type="radio" name="lcmoptions" id="terminate" value="terminate" /> Terminate &nbsp;
    <input type="radio" name="lcmoptions" id="wipe" value="wipe" /> Wipe &nbsp;
    <input type="radio" name="lcmoptions" id="other" value="other" /> Other &nbsp;
    <div>
    Enter text:
        <input type="text" name="textbox" value="test text stuff"/>
        <textarea name="textarea"></textarea>
    </div>
    

    http://jsfiddle.net/LthAs/

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

Sidebar

Related Questions

Say I have this radio: <form name=myForm> <input type=radio name=foo value=1> 1 <input type=radio
I have jQuery code which looks something like this on Button1 Click $('table.result_grid tbody
So, I have radio boxes of the form <li><input type=radio name=names value=blah><a>Some text (blah)</a></li>
I have an HTML form with some radio buttons like these: <form action =
So I have this form, sent via jQuery ajax, but I'd like to validate
I have a form with several radio buttons grouped by the same name, and
If I have 3 radio buttons, is there a way through jQuery of finding
I have a problem selecting a checked radio button with jquery. The radio buttons
I have the following Radio Buttons: <form id=bg action=#> <span id=questionText>Question Test Here:</span><br/> <input
I have a simple form. Input fields, checkboxes, radio buttons and finally SUBMIT button.

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.