Set Select Box value with yes/no variable.

John Snow1
Kilo Expert

Hello,

I am working on a Catalog Client script that will automatically select a choice from a list select box when a separate yes/no variable is toggled to "Yes" I used an alert to verify that my IF statement is working, and it seems to be working fine. The issue I am having is with the g_form.setValue(). I have tried using the text option that is in the choice list and the value and have had no luck with automatically changing the choice selection.

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

   //Type appropriate comment here, and begin script below
   if (g_form.getDisplayValue('u_hasData') == "yes") 
	   {
		   alert(g_form.getDisplayValue('u_hasData')); 
		  g_form.setValue('pre_disposal', 'IT');
	   }
}

 

 

any suggestions?

1 ACCEPTED SOLUTION

Allen Andreas
Administrator
Administrator

Try:

if (g_form.getValue('u_hasData') == 'Yes')

or

if (g_form.getValue('u_hasData'== 'yes')

 I forget which one works

 

and for this:

g_form.setValue('pre_disposal', 'IT');

 

Is IT...the value of an eligible select box option? Like does it already exist? If so...it should work, if not, and you're trying to force it in there, see above post from another user on how to add it.

You'd need to make sure that for the variable select box 'pre_disposal' that it has a select box choice of IT as the value, not the name, but value.

Please mark reply as Helpful/Correct, if applicable. Thanks!


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

View solution in original post

3 REPLIES 3

Harsh Vardhan
Giga Patron

are you setting the value in select box type variable?

if yest try with g_form.addOption()

Allen Andreas
Administrator
Administrator

Try:

if (g_form.getValue('u_hasData') == 'Yes')

or

if (g_form.getValue('u_hasData'== 'yes')

 I forget which one works

 

and for this:

g_form.setValue('pre_disposal', 'IT');

 

Is IT...the value of an eligible select box option? Like does it already exist? If so...it should work, if not, and you're trying to force it in there, see above post from another user on how to add it.

You'd need to make sure that for the variable select box 'pre_disposal' that it has a select box choice of IT as the value, not the name, but value.

Please mark reply as Helpful/Correct, if applicable. Thanks!


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

"You'd need to make sure that for the variable select box 'pre_disposal' that it has a select box choice of IT as the value, not the name, but value."

That did it. I had set the value to a numeric value and tired using that before by using

g_form.setValue('pre_disposal', '5')

and had no luck.

 

Changing it to the value of the IT option to "IT" and using

g_form.setValue('pre_disposal', 'IT') 

Worked like a charm. 

 

Thank you sir.