0

I have a hidden element called #inf_option_isGmail that is a checkbox. I have some code on the page, that checks if it a field has a gmail address in it, so I can do something special to handle their promotions tab.

I tried to work this out from this question or this question but I cannot.

Here is my code:

jQuery( "#inf_field_Email" )
  .keyup(function() {
    var str = jQuery( this ).val();
    if (str.toLowerCase().indexOf("gmail") >= 0) {
        jQuery('#inf_option_isGmail').prop('checked', true);
    }
  })
  .keyup();
[]

Problem is I can't make it actually check the box :(

<div style="display:none;">      
      <input id="inf_option_IsGmail" name="inf_option_isGmail" type="checkbox" value="2172">         
    </div>

This is all on page: http://ww2.auspiciousartsincubator.org/artist-grant-crossroads/d.html?inf_custom_ReferralQScr=blah

any ideas why this isn't working?

I have tried

jQuery('#inf_option_isGmail').click();
jQuery('#inf_option_isGmail').attr('checked',true);
jQuery('#inf_option_isGmail').each(function(){ this.checked = true; });
Community
  • 1
  • 1
Craig Lambie
  • 2,888
  • 2
  • 14
  • 17
  • This isn't an answer so much as debugging help, but if you throw a `console.log` or two into your keyup function, does it fire? Do the right logs fire with the right values, depending on where you put them and what values you try and log? If you log `jQuery("#inf_option_isGmail")` is an extended element returned? That would be the first thing I tend to do in a situation like this. – stratedge Aug 18 '16 at 02:41
  • try using `attr` instead, `prop` is only added in from jquery 1.6 and above – kasperite Aug 18 '16 at 02:45

2 Answers2

1

You got an error in your selector - it should have capitalized IsGmail.

Change

jQuery('#inf_option_isGmail').attr('checked',true);

to

jQuery('#inf_option_IsGmail').attr('checked',true);

Nikolay Ermakov
  • 5,031
  • 2
  • 11
  • 18
0

your html ID is inf_option_IsGmail and your jQuery selector is inf_option_isGmail

isGmail in jQuery must be IsGmail :)

Ahmad Hajjar
  • 1,796
  • 3
  • 18
  • 33