Expand my Community achievements bar.

Problem creating simple Script Object

Avatar

Level 4

I have not been able to get this simple Script Object to work. It should be simple, but this is my first script object, and as I'm new to LS and JS I'm not very adept at writing JS (functions, variables, you name it).

Would someone be so kind as to help me get this easy one down so I can study it and see where I went wrong?

What this script object would do is call a function that checks the value of two check boxes. If one checkbox's value = 1 then the textstring "Male" gets written to the lower text box. If the other box's value = 1, then "Female" is written to the same box (and of course, Male is deleted)

Thanks!

Graham

3 Replies

Avatar

Level 10

Hi Graham,

The first problem I found is that JavaScript names are case sensitive and you are referring to it in lower case, then the JavaScript comparison operator is "==" not "=".

Have a look in the calculate event of your text box to see how I would do it ... assigning the textbox the result of the function not passing in the textbox to the function, I try and make them ignorant of the form structure.

In this case I’m not sure why you didn’t choose to use a radiobutton list (or exclGroup in Designer terminology) so I’ve added an example of that as well.

Hope it helps.

Bruce

Avatar

Level 4

Bruce,

Thank you for taking the time to look at this. I appreciate it greatly. This is a contrived example I put together primarily to study Script Objects. I was also practicing using JS to make different things happen within a form. That is the reason for not using Radio Buttons.

I can't believe a stumbled on a wrong case issue. Perhaps I'd been working on this too long.

I'm new to JS, have been studying books religiously for a few weeks now. But your use of square brackets in your added example has opened a whole new can of worms!

//this.rawValue = ["", "MaLe", "FemaLe"][Number(Gender.rawValue)];

Is that the only way that could be written? Besides probably being more succinct, is there any particular reason using square brackets in this situation is preferable? So far, I'm only used to seeing square brackets being used in reference to instances... which is hard enough for me to comprehend. What is your reason for using them here?

Thanks!

Graham

Avatar

Level 10

Hi Graham,

Adobe Reader using the same JavaScript engine as used by Mozilla (called SpiderMonkey) and their website has a lot of information about learning and using JavaScript, https://developer.mozilla.org/en/JavaScript. Only problem is Mozilla has moved on to version 1.8.1 and I think Reader is still on 1.5, but they make it easy to work out what features are available in what version.

Array literals are good if you aren't going to reuse them, maybe a better alternative would be to reference the captions of the checkboxes or radiobuttons.

Bruce

Writing ["", "MaLe", "FemaLe"] creates an array literal so I could have written something like;

var

genders = new Array("", "MaLe", "FemaLe");

var

gender = Number(Gender.rawValue);

this.rawValue

= genders[gender];