Click here to Skip to main content
15,905,782 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hai Friend's,


I have a small problem with my project ...
In my web form i have 5 radio buttons beside radio buttons i have 5 text boxes and i want to highlight the text box background color when i click on the particular radio button
Posted

place this style tag in head part
CSS
<style type="text/css">
      
        .mystyle
        {
            color: Blue;
            background-color: Red;
            border: 2px solid #DCDCDC;
        }
        .nocolor
        {
            background-color: White;
        }
    </style>


place this script in head part
JavaScript
<script type="text/javascript">
       var previousbox = 'TextBox1';
       function changecolor(rid) {

           document.getElementById(rid).className = "mystyle";
           document.getElementById(previousbox).className = "nocolor";
           previousbox = rid;
       }
   </script>

and your design code should like this

ASP.NET
<table width="50%">
                    <tr>
                        <td>
                            <input type="radio" id="Radio1" onclick="changecolor('TextBox1')" name="a" /><asp:TextBox
                                ID="TextBox1" runat="server"></asp:TextBox>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <input type="radio" id="Radio2" onclick="changecolor('TextBox2')" name="a" /><asp:TextBox
                                ID="TextBox2" runat="server"></asp:TextBox>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <input type="radio" id="Radio3" onclick="changecolor('TextBox3')" name="a" /><asp:TextBox
                                ID="TextBox3" runat="server"></asp:TextBox>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <input type="radio" id="Radio4" onclick="changecolor('TextBox4')" name="a" /><asp:TextBox
                                ID="TextBox4" runat="server"></asp:TextBox>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <input type="radio" id="Radio5" onclick="changecolor('TextBox5')" name="a" /><asp:TextBox
                                ID="TextBox5" runat="server"></asp:TextBox>
                        </td>
                    </tr>
                </table>
 
Share this answer
 
v2
Comments
Ranjith Reddy CSE 26-May-12 7:44am    
Dear Friends,
This is Successful answer ..........

Design Page
===========

<asp:RadioButtonList ID="RadioButtonList1" runat="server" AutoPostBack="True"
onselectedindexchanged="RadioButtonList1_SelectedIndexChanged">
<asp:ListItem Value="Red">Red
<asp:ListItem Value="green">Green

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

Code behind
============
Just Include this Name space also.........

using System.Drawing;

protected void RadioButtonList1_SelectedIndexChanged(object sender, EventArgs e)
{
if (RadioButtonList1.SelectedValue == "Red")
{
TextBox1.BackColor = Color.Red;
}
else
{
TextBox1.BackColor = Color.Green;
}
}


Try this Cute answer.........which is helpfil to u.
Dear Friends,
This is Successful answer ..........

Design Page
===========
ASP.NET
<asp:RadioButtonList ID="RadioButtonList1" runat="server" AutoPostBack="True"
            onselectedindexchanged="RadioButtonList1_SelectedIndexChanged">
            <asp:ListItem Value="Red">Red
            <asp:ListItem Value="green">Green

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

Code behind
============
Just Include this Name space also.........
C#
using System.Drawing;

protected void RadioButtonList1_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (RadioButtonList1.SelectedValue == "Red")
        {
            TextBox1.BackColor = Color.Red;
        }
        else
        {
            TextBox1.BackColor = Color.Green;
        }
    }


Try this Cute answer.........which is helpfil to u.
 
Share this answer
 
v2
Hi,

try this

XML
<asp:RadioButtonList ID="RadioButtonList1" runat="server" AutoPostBack="True"
            onselectedindexchanged="RadioButtonList1_SelectedIndexChanged">
            <asp:ListItem Value="Red">Red</asp:ListItem>
            <asp:ListItem Value="green">Green</asp:ListItem>
        </asp:RadioButtonList>
        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>


Code Behind
C#
protected void RadioButtonList1_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (RadioButtonList1.SelectedValue == "Red")
        {
            TextBox1.BackColor = Color.Red;
        }
        else
        {
            TextBox1.BackColor = Color.Green;
        }
    }


Best Luck
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900