Expand my Community achievements bar.

Using newText more than once in a form

Avatar

Level 4

I have a form with several hidden subforms, which become visible depending on what the user selects in the dropdown list for each subform. The problem is that my script doesn't work for all the subforms. I've come across some information about this (copied below), and I've included my event scripts for the three subforms. I've tried using a var, like this: "var newValue = this.boundItem(xfa.event.newText);", but that doesn't solve the problem. I've also tried both "switch...case" and "if...else." Neither one provides the answer. Thank you for any suggestions you might have or for pointing me toward a source of relevant information.

***********************From the Forum

http://forums.adobe.com/message/1358815#1358815

The xfa.event.newText will have the value of the selected dropdown will focus is still on the dropdown. The rawValue property will not be populated until you leave the dropdown. So depending on when you want the value will determine which property to use. Note that the xfa.event.newText will return the value and not the text of the dropdown (assuming you have both set).

The xfa.event.newText will give you what was entered into a field while it still has focus. In a DD List the selected values are returned. In a textField you would get the chars that are typed into the field. Once focus leaves the field the event.newText is cleared and it is ready for the next field to populate it.

http://forums.adobe.com/thread/694464?tstart=0
Also you only get one shot at xfa.event.newText .....if you are using it earlier in the script it will be gone the second time you use it. So put it in a variable right away, then you can reuse the variable.

**********************From my form

form1.injurySubformPage1.workLocationDdl::change - (JavaScript, client)
sedgwickSubform.presence = "hidden";
benefitsSubform.presence = "hidden";
custServSubform.presence = "hidden";

var newValue = this.boundItem(xfa.event.newText);
switch (newValue){
    case "assoc":
          sedgwickSubform.presence = "visible";
            break;
       
    case "benefits":
            benefitsSubform.presence = "visible";
                break;
               
    case "custserv":
            custServSubform.presence = "visible";
                break;
        
    }

next dropdown

assocInfoSubform.presence = "hidden";
custInfoSubform.presence = "hidden";

switch (newValue){
    case "associate":
          sedgwickSubform.presence = "visible";
            break;
       
    case "customer":
            benefitsSubform.presence = "visible";
                break;      
    }

last dropdown

form1.injurySubformPage2.seekingMedicalTreatmentDdl::change - (JavaScript, client)
physicianSubform.presence = "hidden";


switch (newValue){
    case "yes":
          physicianSubform.presence = "visible";
            break;
       
    case "no":
            physicianSubform.presence = "hidden";
                break;   
    }

12 Replies

Avatar

Former Community Member

If you look at the Javascript console are you getting any errors? Also I woudl put out a message after you assign newValue to ensure you are getting what you thing you are getting in that command.

Paul

Avatar

Level 4

How and where would I put that message? It's a javascript alert box, isn't it?

I began to think the problem is related to .newText being on the second page. So I added a new var like this:

form1.injurySubformPage2.seekingMedicalTreatmentDdl::change - (JavaScript, client)
physicianSubform.presence = "hidden";

var newValue2 = this.boundItem(xfa.event.newText);
switch(newValue2 ) {

    case "yes":
        physicianSubform.presence = "visible";
    break;
   
    case "no":
        physicianSubform.presence = "hidden";
    break;
}

If I click the dropdown first, it works. But then the other two dropdowns earlier in the form, on page 1, don't fire. If I click on the first dropdown on page 1, it works, and so does the second dropdown. But then the third dropdown doesn't work. Can you think of any reason for this?

Avatar

Former Community Member

Put the message before the Switch statement and the var newValue2 statement.

Paul

Avatar

Level 4

What is the javascript message? alert('message') isn't right. Below are the scripts for each dropdown list now, after I made some changes. I also made another test form with three dropdowns and their respective subforms on one page. They all work normally, with select...case statements, like the ones below.

*********************dropdown #1

form1.injurySubformPage1.workLocationDdl::change - (JavaScript, client)
sedgwickSubform.presence = "hidden";
benefitsSubform.presence = "hidden";
custServSubform.presence = "hidden";

var newValue = this.boundItem(xfa.event.newText);
switch (newValue){
    case "assoc":
          sedgwickSubform.presence = "visible";
            break;
       
    case "benefits":
            benefitsSubform.presence = "visible";
                break;
               
    case "custserv":
            custServSubform.presence = "visible";
                break;
        
    }

***************** dropdown #2

form1.injurySubformPage1.typeOfIncidentDdl::change - (JavaScript, client)
assocInfoSubform.presence = "hidden";
custInfoSubform.presence = "hidden";wn #3

var newValue = this.boundItem(xfa.event.newText);
if (xfa.event.newText == "associate"){

          assocInfoSubform.presence = "visible";


} else {
          custInfoSubform.presence = "visible";
        
    }

************************dropdown#3

form1.injurySubformPage2.seekingMedicalTreatmentDdl::change - (JavaScript, client)
physicianSubform.presence = "hidden";

var newValue = this.boundItem(xfa.event.newText);

switch(newValue) {

    case "yes":
        physicianSubform.presence = "visible";
    break;
   
    case "no":
        physicianSubform.presence = "hidden";
    break;
}

Avatar

Former Community Member

its app.alert("message")

In your case you will want to say app.alert(newValue)

If you cannot determine what the issue is from that I suggest that you send me the form and I will have a look ....send it to LiveCycle8@gmail.com and include a description of how to reproduce the issue in  the email.

Paul

Avatar

Level 4

I'm assuming that I have to declare the variable once, up in the script for the first dropdown.

var newValue = this.boundItem(xfa.event.newText);

I'm also assuming that the script below sets the default presence for objects, and that I set this once.

form1.injurySubformPage1.workLocationDdl::change - (JavaScript, client)
sedgwickSubform.presence = "hidden";
benefitsSubform.presence = "hidden";
custServSubform.presence = "hidden";

Avatar

Former Community Member

The variable is only available for the duration of the script ...so you would have to declare the var in each script.

The presence is set by the script and it will last for the duration of the form's session. Once the form is closed that setting is lost ...unless you preserve script changes in the Form Properties/Defaults tab.

Paul

Avatar

Level 4

Experimenting, I made a new test form with all three dropdowns and their respective subforms on one page. Voila! They all work perfectly! However, when I move the third dropdown and its one subform to a second page, it doesn't work, if I've already click on the first two dropdowns. Is there an explanation for this behavior?

Avatar

Former Community Member

Need to see the form in action to determine what is wrong. Cna you send it to the address I gave you earlier?

Paul

Avatar

Level 10

You may try placing the fully qualified name to the DD list..

for Example

     form1.injurySubformPage1.sedgwickSubform.presence = "visible";

Thanks

Srini

Avatar

Level 4

Here's what the javascript console shows.

newValue is not defined
4:XFA:form1[0]:subformPage2[0]:seekingMedicalTreatmentDdl[0]:change
newValue is not defined
4:XFA:form1[0]:subformPage2[0]:seekingMedicalTreatmentDdl[0]:change

Avatar

Level 4

Sini,

I just tried the fully-qualified name to the subform with the same result. I'm going to send Paul the form and see what he makes of it.