These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

Display value working opposite of what I expected

Lisa Gielczyk
Registered: Jul 13 2009
Posts: 6

Hello everyone,

I am working with the display property for the first time, and it's working opposite of what I expected. This is my function:

function RadioButtonRequired()
{
      //assign a variable for the Radio Button
    var rb2=getField("Slide");
 
    //assign variables for the combobox fields
    var s1=getField("11_6");
    var s2=getField("11_7");
 
    /*test the radio buttons--if yes is selected,
    comboboxes become visible*/
    if(rb2.value == "Yes")
       {
          s1.display=display.visible;
          s2.display=display.visible;
 
       }
 
    else
       {
         s1.display=display.hidden;
         s2.display=display.hidden;
 
       }
 
}

I have an Action on each Radio Button to run the JavaScript RadioButtonRequired();.

When I test it by clicking on the Yes Radio Button, the fields become hidden instead of visible. When I click the No Radio Button, the fields become visible.

Can anyone tell me what I'm missing?

Thanks,
Lisa Gielczyk

thomp
Expert
Registered: Feb 15 2006
Posts: 4411
What is the trigger used to run the script? MouseUp or MouseDown?

The issue is that the value is following the action, rather that Action following the value change. So the script must be being called with the wrong trigger.

Mouse Down preceeds the radio button value being changed. You can test this out by putting the cursor over the radio button pressing down on the mouse button, do not let up on the mouse. Is your action happening? Did the radio button value change? Now move the cursor off the radio button and lift up on the mouse button. Try this again but lift up on the mouse while it is over the radio button. See the difference? The radio button value only changes on the mouse up.

All changes are made only on Mouse Up, so this is where the script should be.

On another note: You've done this correctly in one sense, by using a document level function. But it's bad form to use "getField()" to acquire field the script is being called for. Instead, use "event.target". So your "if" would look like this:
    if(event.target.value == "Yes"){...

Thom Parker
The source for PDF Scripting Info
[url=http://www.pdfScripting.com]pdfscripting.com[/url]

The Acrobat JavaScript Reference, Use it Early and Often
[url=http://www.adobe.com/devnet/acrobat/javascript.php]http://www.adobe.com/devnet/acrobat/javascript.php[/url]

Then most important JavaScript Development tool in Acrobat
[url=http://www.pdfscripting.com/public/34.cfm#JSIntro][b]The Console Window (Video tutorial)[/b][/url]
[url=http://www.acrobatusers.com/tutorials/2006/javascript_console][b]The Console Window(article)[/b][/url]

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script

Lisa Gielczyk
Registered: Jul 13 2009
Posts: 6
Hi Thom,

Thanks for the advice about using event.target.value instead of getField()! I'll definitely use that from now on.

My JavaScript function call was on the Mouse Up Event, but.... (I must have been coding in my sleep, because I don't remember doing it) the function call was also on my field, which made the value change a second time.

It's all in the details, and it took me awhile to find that one.

Thanks!
Lisa
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
Ahh, so it was being called from the wrong place, just a completely different wrong place than I thought. Murphy's Law at work;) Good Catch

Thom Parker
The source for PDF Scripting Info
[url=http://www.pdfScripting.com]pdfscripting.com[/url]

The Acrobat JavaScript Reference, Use it Early and Often
[url=http://www.adobe.com/devnet/acrobat/javascript.php]http://www.adobe.com/devnet/acrobat/javascript.php[/url]

Then most important JavaScript Development tool in Acrobat
[url=http://www.pdfscripting.com/public/34.cfm#JSIntro][b]The Console Window (Video tutorial)[/b][/url]
[url=http://www.acrobatusers.com/tutorials/2006/javascript_console][b]The Console Window(article)[/b][/url]

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script