Click here to Skip to main content
16,004,602 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have dropdown control in asp.net C#. Which is below.

XML
<td style="text-align: left">
                                               <asp:DropDownList ID="ddlCurrencyUnit" runat="server" CssClass="textarea" Width="65px" AutoPostBack="True" OnSelectedIndexChanged="ddlCurrencyUnit_SelectedIndexChanged">
                                                   <asp:ListItem Value="INR" Selected="True">INR</asp:ListItem>
                                                   <asp:ListItem Value="USD">USD</asp:ListItem>
                                                   <asp:ListItem Value="EURO">EURO</asp:ListItem>
                                               </asp:DropDownList>
                                               <asp:TextBox ID="txtCurrencyConversationAmt" runat="server" CssClass="textarea" Width="50px"></asp:TextBox>
                                           </td>



I want to visible true my textbox if my Dropdown value is not INR using Javascript
Posted

Try like this.

HTML
<script type="text/javascript">
function makeVisible()
{
    var value = document.getElementById("ddlCurrencyUnit").options[document.getElementById("ddlCurrencyUnit").selectedIndex].value;

    //do something with the value
    if(value=="INR")
      document.getElementById("txtCurrencyConversationAmt").style.display = 'none';
    else
      document.getElementById("txtCurrencyConversationAmt").style.display = '';
}
</script>

call the function on onchange
ASP.NET
<asp:DropDownList ID="ddlCurrencyUnit" OnChange="makeVisible();" runat="server">
.
.
</asp:DropDownList>
 
Share this answer
 
Comments
viralchauhan 24-Sep-13 8:46am    
I have tried this solution But it's not working. Please give me some other solution.
Thomas ktg 24-Sep-13 8:47am    
Give me the problem you are facing with this.
Thomas ktg 24-Sep-13 8:57am    
You must remove the Server side event ddlCurrencyUnit_SelectedIndexChanged and set AutoPostBack="False". Then this code would work fine.
Hi Viral,

The solution I am giving to you is in jquery.

Sample Code:
Asp Code:
ASP.NET
<asp:dropdownlist id="ddlCurrency" runat="server" xmlns:asp="#unknown">
    <asp:listitem text="INR" value="0"></asp:listitem>
    <asp:listitem text="US Dollar" value="1"></asp:listitem>
    <asp:listitem text="Pound" value="3"></asp:listitem>
    <asp:listitem text="Yen" value="4"></asp:listitem>
 </asp:dropdownlist>
 <asp:textbox id="txtHideMe" runat="server" xmlns:asp="#unknown"></asp:textbox>


jquery code:
JavaScript
<script type="text/javascript" language="javascript">
        $(document).ready(function ()
        {
            $("select[id$='ddlCurrency']").change(function ()
            {
                var value = this.value;
                var txtHideMe = $("input[id$='txtHideMe']");
                if (value == 0)//i.e INR
                {
                    txtHideMe.css({ 'display': 'none' });
                }
                else
                {
                    txtHideMe.css({ 'display': 'block' });
                }
            });
        });
    </script>


Hope this helps!
 
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