JQuery work in Firefox and Chrome yet not in IE 9.

I have a radio buttons on a web page. When the radio button is "On"/selected then I have a label control display a text message. When the radio button is "Off"/Un selected, I display a different line of text. This works great in all of my browsers except Internet Explorer. I am using IE 9, and have ven tried compatibility mode, yet it won't work in IE.

I put alert boxes in the code and IE is flat out not executing the JQuery below. Can someone help me out? I am stuck. Attached is the actual code

<script type="text/javascript">
 
    jQuery(document).ready(
 
        function ($) {
 
 
 
            $('#radioButtonNoToSSN').click(function (event) {
 
                if ($(this).attr('checked')) {
 
                    document.getElementById('ApplicantSocialSecurityNumberLabel').textContent = "US Visa, Green Card Number";
 
                }
 
                else {
 
                    document.getElementById('ApplicantSocialSecurityNumberLabel').textContent = "Social Security Number *";
 
                }
 
            });
 
          

        });
     
 
</script>

Open in new window

JQueryProblem.txt
LVL 2
brgdotnetcontractorAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

RobOwner (Aidellio)Commented:
Thinking you should check if the checkbox is checked like this:

 if ($(this).attr('checked') === "checked") {

Open in new window

0
leakim971PluritechnicianCommented:
Try this :
jQuery(document).ready(function ($) {
    $('#radioButtonNoToSSN').change(function (event) {
        var str = $(this).is(':checked')?"US Visa, Green Card Number":"Social Security Number *";
        $('#ApplicantSocialSecurityNumberLabel').text(str);
    });
});

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
brgdotnetcontractorAuthor Commented:
Actually the problem was with the Java script that changed out the Text. I was using Java Script, and instead used JQuery. It now works.
0
Starting with Angular 5

Learn the essential features and functions of the popular JavaScript framework for building mobile, desktop and web applications.

RobOwner (Aidellio)Commented:
Can you please post the relevant code that you said held the issue for you?

If neither of @leakim971's code or mine actually contributed to the answer then you shouldn't accept them as solutions.  Instead you should post what actually fixed your issue and either accept that as the answer and/or accept our posts as assisted if they did in fact assist you.
0
brgdotnetcontractorAuthor Commented:
Thanks tagit. You guys were very helpful. I am away from work and will make sure I post the actuall solution in the next few day. Thanks so much.
0
brgdotnetcontractorAuthor Commented:
Here is my solution. My apologies for lopsiding the points when awarding them.

if ($('#checkboxNoToSSN').attr('checked'))
  {

  document.getElementById('ApplicantSocialSecurityNumberLabel').textContent = "US Visa";
  }
  else
      {

 document.getElementById('ApplicantSocialSecurityNumberLabel').textContent = "Social Security Number *";

  }
0
RobOwner (Aidellio)Commented:
http://jsbin.com/idiQiQ/1/edit  Does that demo work for you?

The solution here is that ".attr('checked')" didn't return what you needed it to. To detect if an input element is checked (radio/checkboxes) you need to use a selector ':checked' if you are to use jQuery.
 
Here is a demo of @leakim971's code working: http://jsbin.com/IgEcUxa/1/edit. Did you actually try that code?  This is the actual solution.

I would also suggest working in one style or the other ie jQuery or pure javascript.  Your if...else.. can be greatly simplified as @leakim971 has shown.
0
brgdotnetcontractorAuthor Commented:
Respectfully. I am very sure the code works. However it is possible I made a mistake. I am travelling and won't be able to double check the code until Tuesday. Will get back with you then. Thanks.
0
RobOwner (Aidellio)Commented:
Thanks for the reply - I couldn't get your code to work see my previous post #a39473677.
My ultimate aim is to have an obvious solution if someone was to come across this post with a similar issue, which is why i'm being so persistent :)

You will most certainly be better off using jQuery and not mixing with pure javascript.
0
brgdotnetcontractorAuthor Commented:
So sorry gentlemen. I am wrong. I posted the wrong code. Blush blush. You need a slap button on your side to slap me one up side of the head. And I need a button on this side to buy you a beer. Both of you guys. LOL. Just kidding of course, however I feel like an idiot right now. Again my apologies. Here is the actual code that worked.

Dear tagit Sir, how would you like me to reallocate the points?

if ($('#checkboxNoToSSN').attr('checked'))
{
  $('[id$=ApplicantSocialSecurityNumberLabel]').text("Visa");
}
else
{
{
  $('[id$=ApplicantSocialSecurityNumberLabel]').text("Social Security Number");
}
0
RobOwner (Aidellio)Commented:
Not a problem at all @brgdotnet! I was starting to sweat thinking "what have I missed!"

I believe leakim971's post #a39451407 is worth the points.  It's exactly the same as what you've posted, just written differently.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
jQuery

From novice to tech pro — start learning today.