Click here to Skip to main content
15,886,026 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am creating a website which has two div tags and two radio buttons. The div is to be displayed on the basis of radio button selected. On page load I pass the value of radio button from main page and accordingly I display div. It works well with chrome and firefox but showing problem in IE. I am using IE 11. I have not tried with other versions of IE. My code is as follows:
ASP.NET
<asp:RadioButton ID="mail_stat" Text="Mailwise Statistics" runat="server" GroupName="stat_select" onclick="ch(1)" ClientIDMode="Static" />
   <asp:RadioButton ID="aggegrate_stat" Text="Aggegrate Statistics" runat="server" GroupName="stat_select" onclick="ch(2)" ClientIDMode="Static" />


ASP.NET
<div id="first">
    <table border="0">
        <tr>
            <td>
                         
                <asp:Label ID="lbl_pro_id" runat="server" Text="Promotion Id"></asp:Label> </td>
            <td>
                   
                <asp:TextBox ID="txt_pro_id" runat="server" Width="101px"></asp:TextBox></td>
        </tr>
        <tr>
            <td>
                         
                <asp:Label ID="lbl_sub" runat="server" Text="Subject"></asp:Label></td>
            <td>
                   
                <asp:TextBox ID="txt_sub" runat="server" Width="301px" Height="16px"></asp:TextBox></td>
        </tr>
    </table>
</div>


ASP.NET
<div id="second">
    <table border="0">
        <tr>
            <td>
                        
                <asp:TextBox ID="txtStartDate" runat="server" required="true" placeholder="Start Date"></asp:TextBox></td>
            <td>
                <asp:TextBox ID="txtEndDate" runat="server" required="true" placeholder="End Date"></asp:TextBox></td>
        </tr>
    </table>
</div>


My java script is as follows:
JavaScript
 <%--Javascript for radiobuttion on load--%>              
<script type="text/javascript">
    onload = function () {
        if (mail_stat.checked == true)
        {
            ch(1);
        }
        else if (aggegrate_stat.checked == true)
        {
            ch(2);
        }
    }
</script> 

<%--Javascript for radiobuttion--%>
 <script type="text/javascript">
     $('#first').hide();
     $('#second').hide();
     $('stat2').hide();
     function ch(id) {
         if (id == '1') {
             $('#first').show();
             $('#second').hide();
             $('#stat2').hide();
         }
         else if (id == '2') {
             $('#first').hide();
             $('#second').show();
             $('#stat2').show();
         }
     }
 </script> 

Thank you.
Posted
Comments
Kornfeld Eliyahu Peter 5-Feb-14 6:58am    
You already have jQuery, why not use it for the onload part too?
Ami_Modi 5-Feb-14 7:00am    
How?
Kornfeld Eliyahu Peter 5-Feb-14 7:03am    
http://api.jquery.com/ready/
Ami_Modi 5-Feb-14 7:18am    
Can you help me up with my code. I am new at asp.net and don't know how and where to use jquey in code

I think ie wont be able to resolve mail_stat itself like other browsers hence you would need to get the javascript element by
JavaScript
var mail_stat = document.getElementById('mail_stat')
in your onload function prior to
JavaScript
if(mail_stat.checked == true)...
statement. I'm sure onload would be executing but throwing an error while reaching to mail_stat.checked line as mail_stat would be undefined.
 
Share this answer
 
Comments
Ami_Modi 5-Feb-14 7:36am    
Thanks a lot.. This worked for me..
Hemant__Sharma 5-Feb-14 8:13am    
You are welcome :)
try..


JavaScript
<script type="text/javascript">
 window.onload= function () {
        if (mail_stat.checked == true)
        {
            ch(1);
        }
        else if (aggegrate_stat.checked == true)
        {
            ch(2);
        }
    }
</script> 



OR

XML
<script type="text/javascript">
   function OnLoad () {
        if (mail_stat.checked == true)
        {
            ch(1);
        }
        else if (aggegrate_stat.checked == true)
        {
            ch(2);
        }
    }
</script>


HTML
<body  önload="javascript:OnLoad();">
</body>
 
Share this answer
 
v4
Comments
Ami_Modi 5-Feb-14 7:06am    
Kedar this is not working with IE.
kedar001 5-Feb-14 7:26am    
Check Updated solution...

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