Click here to Skip to main content
12,356,154 members (70,656 online)
Rate this:
 
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 17-Dec-12 6:07am
   
please make sure that in your chrome , JS is enabled...
Sweetynewb 17-Dec-12 6:13am
   
JS is enabled in chrome
Now?
Krunal Rohit 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 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 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
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web01 | 2.8.160621.1 | Last Updated 17 Dec 2012
Copyright © CodeProject, 1999-2016
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