Jump to content

drop down list IE vs crome


paulonline2501

Recommended Posts

Hi,

 

this is not my code but its giving me trouble on a site.

the code works in IE. but in Crome

 

there is a radio button that is defaulted to not show some text.

when the user switches to the other radio button (three are just two) the text is supposed to display.

it works in IE but not Crome.

 

is the text below enough or do you want to see the code for the whole page?

<script type="text/javascript">$(document).ready(function() { $("input:radio[alt-id='test-hide']").change(function() {      if(this.checked && this.value == "Y") {$("div#other-questions").show();}if(this.checked && this.value == "N") {$("div#other-questions").hide();}});$("input:radio[alt-id='test-hide']").change();});
Link to comment
Share on other sites

First, indent your code properly. It's hard to read like that. Here, this is better:

$(document).ready(    function()    {        $("input:radio[alt-id='test-hide']").change(            function()            {                      if(this.checked && this.value == "Y")                {                    $("div#other-questions").show();                }                if(this.checked && this.value == "N")                {                    $("div#other-questions").hide();                }            }        );        $("input:radio[alt-id='test-hide']").change();    });

It looks like you're using a custom attribute alt-id, it might not be the cause of the problem but if other solutions don't work I'd check it out. You should only use valid HTML attributes. You can make a custom attribute valid in HTML 5 by prepending it with data-.

 

In this code you called change() a second time and it might be that it overwrote the previous change() event listener with nothing. Unless there's a good reason for it to be there you probably should remove that line.

 

I can't pinpoint the problem more precisely without seeing the HTML that this Javascript is acting on.

Link to comment
Share on other sites

proper jquery way

if($(this).is(':checked') && $(this).val() == "Y")               {                    $("#other-questions").show(); /* there can only be a single unique id ref other-questions so you don't need div at beginning*/                 }               if($(this).is(':checked') && $(this).val() == "N")                {                    $("#other-questions").hide();                }
Edited by dsonesuk
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...