Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: Javascript
Can anybody tell me why this simple javascript not working in google chrome?
 
<script type="text/javascript" language="javascript">
function getRdoValue()
{
    if(document.getElementById("rdo_yes").checked)
    {
          document.getElementById("dlst_type").disabled=false;
          document.getElementById("dlst_course_wocktube").disabled=false;
    }
    if(document.getElementById("rdo_no").checked)
    {
        document.getElementById("dlst_type").disabled=true;
        document.getElementById("dlst_course_wocktube").disabled=true;
    }
}
</script>
 
ASP.NET Form:
 
<asp:RadioButton ID="rdo_yes" runat="server" Text="Yes" GroupName="rdo1" onChange="getRdoValue();" />
       <asp:RadioButton ID="rdo_no" runat="server" 
Checked="True" Text="No" GroupName="rdo1" onChange="getRdoValue();" />
 
<asp:DropDownList ID="dlst_type" runat="server" Enabled="false" AutoPostBack="True" OnSelectedIndexChanged="dlst_type_SelectedIndexChanged">
        </asp:DropDownList>
<asp:DropDownList ID="dlst_course_wocktube" runat="server" Enabled="false">
        </asp:DropDownList>
Posted 17-Dec-12 0:04am
Comments
Krunal Rohit at 17-Dec-12 6:07am
   
please make sure that in your chrome , JS is enabled...
Sweetynewb at 17-Dec-12 6:13am
   
JS is enabled in chrome
Now?
Krunal Rohit at 17-Dec-12 6:17am
   
still not working ??
ok, for that you've to use CSP (http://developer.chrome.com/stable/extensions/contentSecurityPolicy.html)...
for same example take a look : http://stackoverflow.com/questions/13285296/javascript-not-working-in-chrome-extension-html-desktop-notification
Sweetynewb at 17-Dec-12 6:29am
   
I didnt much understood that example... i need to use external js file right?
from where i can able to download that file?

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

You are making the classical mistake every asp.net developer makes for the first time while writing the javascript .You need to use client ID of the asp.net control. You are using the server id in the javascript. It will NOT work in Chrome as well as any other browser.
 
Use this syntax
 
var b = document.getElementById('<%=Button1.ClientID%>');
  Permalink  
v2
Comments
Sweetynewb at 17-Dec-12 23:44pm
   
My previous code was working i firefox and IE
As you said, i made changes in function, but still its not working.
What is the problem for simple enable and disable?
 
New Code:
function getRdoValue()
{
if(document.getElementById("<%=rdo_yes.ClientID%>").checked)
{
document.getElementById("<%=dlst_type.ClientID%>").disabled=false;
document.getElementById("<%=dlst_course_wocktube.ClientID%>").disabled=false;
}
if(document.getElementById("<%=rdo_no.ClientID%>").checked)
{
document.getElementById("<%=dlst_type.ClientID%>").disabled=true;
document.getElementById("<%=dlst_type.ClientID%>").disabled=true;
}
}

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

  Print Answers RSS
0 Maciej Los 245
1 OriginalGriff 215
2 Manfred R. Bihy 190
3 CHill60 180
4 _Amy 155
0 OriginalGriff 7,395
1 Sergey Alexandrovich Kryukov 6,163
2 Maciej Los 3,754
3 Peter Leow 3,448
4 CHill60 2,702


Advertise | Privacy | Mobile
Web04 | 2.8.140721.1 | Last Updated 17 Dec 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100