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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T13:09:12+00:00 2026-05-27T13:09:12+00:00

I have a RadioButtonList and based on what is selected I need a TextBox

  • 0

I have a RadioButtonList and based on what is selected I need a TextBox to do something different. If the first ListItem is selected, I need the TextBox to allow only 4 numeric values to be entered. If the second ListItem is selected, I need the TextBox to function as usual. I have functions for numeric and length validation that I know work but cannot seem to figure out how to implement those based on which is selected. I included the numeric and length functions with the code below. The main issue I have is determining which is selected and based on that selection, how the TextBox should work.

// Only allows numeric values
function isNumeric(num){
    var charCode = (num.which) ? num.which : event.keyCode;
    if (charCode > 31 && (charCode < 48 || charCode > 57)) { return false; }
    else { return true; } 
}

// Validates TextBox Length
function validateTextBoxLength() {
    var tb = document.getElementById("TextBox1").value;
    if (tb.length > 1 && tb.length != 4) {
        alert("TextBox must be 4 digits.");
        return false;
    }
    return true;
}

// Check for RadioButtonList selection
function rbSelectedValue() {
    var radio = document.getElementsByName('<%= rblSearchType.ClientID %>');
    var tb = document.getElementById("TextBox1").value;
    for (var i = 0; i < radio.length; i++) {
        if (radio[i].checked) {
            // alert("RadioButton 1 Selected");
            if (tb.length > 1 && tb.length != 4) {
                alert("TextBox must be 4 digits.");
                return false;
            }
            else {
            return true;
            }
        }
        else {
        // alert("RadioButton 2 Selected");
        return true;
    }
}

<asp:RadioButtonList ID="RadioButtonList" runat="server" AutoPostBack="true" RepeatDirection="Horizontal" onclick="rbSelectedValue()">
    <asp:ListItem Value="List Item 1" Selected="True">Test 1</asp:ListItem>
    <asp:ListItem Value="List Item 2">Test 2</asp:ListItem>
</asp:RadioButtonList>

<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>

Any help would be greatly appreciated and thank you in advance!

  • 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-27T13:09:13+00:00Added an answer on May 27, 2026 at 1:09 pm

    The onclick event that you have referenced in the RBL’s HTML markup is actually the server-side operation.

    In order to fire the onclick event on the client side, you need to add the onclick event to the RBL’s attributes in codebehind:

    RadioButtonList.Attributes.Add("onclick", "rbSelectedValue()");
    

    Update

    I have never used the document.getElementsByName approach to get the RBL data, so I can’t tell you whether or not this is causing the problem, but I can tell you what works for us. We use the following code to successfully extract the currently selected value from the RBL, where the parameter is the ClientID of the RBL:

    function getRadioListSelectedValue(sName) {
        var theList = document.getElementById(sName);
        var returnVal = ''; //empty string, not null
    
        if (theList) {
            for (var i = 0; i < theList.childNodes.length; i++) {
                if (theList.childNodes[i].name == sName) {
                    if (theList.childNodes[i].checked) {
                        returnVal = theList.childNodes[i].value;
                        break;
                    }
                }
            }
        }
        return returnVal;
    }
    

    I would suggest trying this method to get your currently selected value.

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

Sidebar

Related Questions

I have this code <asp:RadioButtonList ID=rblSplitWeek runat=server> <asp:ListItem selected=true>No Choice</asp:ListItem> <asp:ListItem Text = First
I have this code: <asp:RadioButtonList ID=rblExpDate runat=server > <asp:ListItem Selected=True Text=No expiration date></asp:ListItem> <asp:ListItem
I have a RadioButtonList with two ListItems included: <asp:RadioButtonList runat=server ID=optRollover OnSelectedIndexChanged=RolloverOptionSelected AutoPostBack=true> <asp:ListItem
I have a radiobuttonlist; when item[1] is clicked a textbox is displayed and my
I have a RadioButtonList <asp:radiobuttonlist runat=server id=rblList> <asp:listitem>s1</asp:listitem> <asp:listitem>s2</asp:listitem> <asp:listitem>s3</asp:listitem> <asp:listitem>s4</asp:listitem> </asp:radiobuttonlist> In my
I have the following ASP.NET RadioButtonList: <asp:RadioButtonList ID=rbl runat=server> <asp:ListItem Text=Type1 Value=1 /> <asp:ListItem
I have two radiobuttonlist and one checkboxlist on the page. Ideally based on the
I have a RadioButtonList: <p> <label for=rblIAm>I am</label> <asp:RadioButtonList ID=rblIAm ValidationGroup=RegForm runat=server> <asp:ListItem Text=Gay
i have a question: <div> Is hacking good?</div> <div> <asp:RadioButtonList ID=1question runat=server RepeatDirection=Horizontal> <asp:ListItem
I have a radiobuttonlist which display a list of images based on the extension,

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.