Jump to content

drop down list IE vs crome

Recommended Posts



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 post
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 post
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 post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...