The Value of --None-- in onChange Client Script

yundlu316
Kilo Guru

Hi Everyone, I'm trying to write a simple onChange client script that clears values based on an answer:

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
	if (isLoading || newValue==='') {
		return;
	}

	if(g_form.getValue('relation_to_employee').indexOf("child") == -1) {
		g_form.clearValue('x_dnf_gw_found_type_of_child');
		g_form.clearValue('x_dnf_gw_found_dependent');
	} 
}

So if Relation to Employee does not equal "child" then I want to clear the values for Type of Child and Dependent fields.  This works fine, but the Relation to Employee drop down has "-- None --'" and for some reason, this doesn't work.  I've tried changing my if statement to the following but it still doesn't work:

if(g_form.getValue('relation_to_employee', '!=','child') || g_form.getValue('relation_to_employee','')){

Any suggestions on how to fix this?  Thanks!

 

1 ACCEPTED SOLUTION

Jace Benson
Mega Sage

The option of "--None--" has a value of "".  If you change your script to this it should work;

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
	if (isLoading) {
		return;
	}

	if(g_form.getValue('relation_to_employee').indexOf("child") == -1) {
		g_form.clearValue('x_dnf_gw_found_type_of_child');
		g_form.clearValue('x_dnf_gw_found_dependent');
	} 
}

View solution in original post

5 REPLIES 5

Jaspal Singh
Mega Patron
Mega Patron

You can try,

var relemp=g_form.getValue('relation_to_employee');
alert('Relation to emp is '+relemp);

if(relemp=='' || relemp!='child'){

 

Thanks,

Jaspal Singh

 

Hit Helpful or Correct on the impact of response.