Expand my Community achievements bar.

Can one assign a numerical value to a variable?

Avatar

Level 4

Hi All,

Good afternoon,

I am currently working on a form that has strings as values in 2 different listboxes, and depending on what is selected a message pops up. Here is the script I wrote, but it does not seem to work right

var a=aKlaclistbox.raWvalue=="SSK";

var b=bZlaslistbox.raWvalue=="SGT";
a.value=1;
b.value=2;
if(a > b){
    xfa.host.messagebox("You cannot select a lower officer as the rating officer");

  }

It does not work, and I am just wondering if there is any way I can get around it so that I can compare the values. I need help from anyone on this forum.

Thanks

v/r

Tammy

3 Replies

Avatar

Level 10

You've got some coding errors and watch out for capitalization (rawValue not raWvalue).

The following won't work as far as I know but I'm not the best JavaScript programmer around:

var a=aKlaclistbox.raWvalue=="SSK";

var b=bZlaslistbox.raWvalue=="SGT";

"value" is only used for global variables, these would just be a = 1, etc.

a.value=1;

b.value=2;

I think for what you are trying to do I would assign values to the items in the list box using the Binding tab on the Object palette. SSK would equal 1, SGT would equal 2, etc.

Then you could do a compare of the two values:

if (Klaclistbox.rawValue > Zlaslistbox.rawValue) {

   xfa.host.messagebox("You cannot select a lower officer as the rating officer");

}

Avatar

Level 4

Good morning Jono, and thank you. Actually, SSK and SGT were values assigned to Sergeant, and Senior Sergeant in the list box using the Binding tab on the Object palette. So, on selection it displays SSK, and SGT, respectively. This makes the process difficult to make comparison. This is the simple reason why I am trying to see how I can use variables to assign values of 1, and 2 to the items. Hence, I have this code.

var a=aKlaclistbox.raWvalue=="SSK";

var b=bZlaslistbox.raWvalue=="SGT";

a.value=1;

b.value=2;

if (Klaclistbox.rawValue > Zlaslistbox.rawValue) {

   xfa.host.messagebox("You cannot select a lower officer as the rating officer");

}

Thanks, again

Avatar

Level 10

There's probably a better way of doing this, as, depending on how many ranks you have, it could get cumbersome. Like using an array or something like that but not sure how to accomplish that.

If there are a lot of ranks to compare I think I'd suggest reworking things so that you can use the numeric value of the list box, it will be much easier in the long run.

As I mentioned above, I don't think the following is valid code:

var a=aKlaclistbox.raWvalue=="SSK";

Nor is (unless dealing with global variables):

a.value=1;

I think you need to do something like the following (hopefully someone else around here might have a better idea!):

var a;

var b;

if (aKlaclistbox.rawValue == "SSK") {

     a = 1;

}

if (bZlaslistbox.rawValue == "SGT") {

     b = 2;

}

//You would need a series of else/if with the above to map the different rank values.

if (a > b) {

   xfa.host.messagebox("You cannot select a lower officer as the rating officer");

}