Checkbox onchange function

Hi all,

I’m trying to achieve the following:

          0 => 
          array (
            'name' => 'do_not_contact_c',
            'label' => 'LBL_DO_NOT_CONTACT',
	    'custom_code' => '<input type=checkbox id="do_not_contact_c" name="do_not_contact_c" onchange="checkContact(this.value);"',
          ),

do_not_contact_c is a checkbox but I can’t get the “onchange” not even in the HTML final declaration. I mean, it’s like if it didn’t exist.

Any help?

Regards!

Hi Chemimartinez77,

I think you need to explain what you are trying to do, where you are trying to do it etc.

Oh, I’m so sorry. I forgot a lot of things. Ok, here we go. Regardless of the code, in the Edit View of the Contacts module, I have a checkbox and I want it to call a javascript function whenever it changes its state to checked/unchecked. It is because I think it’s the best way to achieve what I actually want. This is that when this checkbox is checked I want to hide/show some other fields and also enable/disable some fields more.

And that’s it. Hope this helps in finding a solution. I keep trying. It’s 4:18 pm and have 'til 7:15 pm to find it.

Thanks again!

Solved:

Here you go!


        6 => 
        array (
          0 => 
          array (
            'name' => 'do_not_contact_c',
            'label' => 'LBL_DO_NOT_CONTACT',
			'customCode' => '<input type="hidden" value="0" name="do_not_contact_c">{if $fields.do_not_contact_c.value == "1"}{assign var="isChecked" value="CHECKED"}{else}{assign var="isChecked" value=""}{/if}<input type="checkbox" id="do_not_contact_c" name="do_not_contact_c" value="1" title="" tabindex="107" onclick="checkContact(this)" {$isChecked}>',
		  ),
          1 => '',
        ),

And the Javascript function:


function checkContact(checkBox){

	cantidadEmails=ContactsemailAddressesTable0.rows.length-1;
	
	if (checkBox.checked){
		do_not_call.disabled='disabled';
		do_not_mail_c.disabled='disabled';
		for (i=0;i<cantidadEmails;i++){
			eval('Contacts0emailAddress'+i+'.disabled=\'disabled\'');
			eval('Contacts0emailAddress'+i+'.style.backgroundColor=\'lightgrey\'');
			eval('Contacts0emailAddressOptOutFlag'+i+'.checked=\'true\'');
		}
	} else {
		do_not_call.disabled='';
		do_not_mail_c.disabled='';
		for (i=0;i<cantidadEmails;i++){
			eval('Contacts0emailAddress'+i+'.disabled=\'\'');
			eval('Contacts0emailAddress'+i+'.style.backgroundColor=\'white\'');
			eval('Contacts0emailAddressOptOutFlag'+i+'.checked=\'\'');
		}
	}
}

Hope this helps someone :wink:

B)

1 Like