Expand my Community achievements bar.

Need script to populate a text field based on the user's choice from a drop-down menu.

Avatar

Level 3

I have a scripting question.  I don't this will be difficult but I can't seem to get it to work.

Here it is:

Question 1 (drop-down menu with 2 choices -yes or no).

If the user chooses "no" from the drop down, I want the next question to automatically be populated with "N/A".

What is the script for this?  If statement? Also, what script event do I place it under?

Thanks a bunch!!!!!

8 Replies

Avatar

Level 3

Can anyone help me with this?  Thanks in advance.

Avatar

Level 10

Pretty simple. let's say ddl1 and dd2 are the field names.

write the below script on CHANGE event of the dd1 field.

if(this.selectedIndex==1)     // when "no" selected

{

     ddl2.rawValue = "NA";

}

Avatar

Level 3

Thank you so much.

I used this and it still isn't working:

if(this.selectedIndex==1) // when "no" selected

{

Page11-Section8-ExternalReviewsAndAudits.AUDITS.Q7b.rawValue = "NA";

}

I'm using JavaScript.

Any idea what I'm doing wrong?

Avatar

Level 3

I'm using JavaScript and used this and it didn't seem to work:

 

if

(this.selectedIndex==1)

// when "no" selected

 

{

Page11

-Section8-ExternalReviewsAndAudits.AUDITS.Q7b.rawValue = "NA";

Any ideas?

Thanks so much!!

Avatar

Level 3

I'm thinking maybe some other code  that I already have in the change event for the first field is messing this up.

Is there a way to write it that would allow me to place it in an event for the 2nd field? and what event would I use?

Avatar

Level 3

I'm thinking maybe some other code that I already have in the change event for the first field is messing this up.

Is there a way to write it that would allow me to place it in an event for the 2nd field? and what event would I use?

Thanks,

Hunter

Avatar

Level 10

If you are using the change event of the drop down list, it will not fire if there is no values selected in the field in the first place...

I suggest it to be in the exit event, or you can just have a value by default like "Choose an option" which will make the change event fire at first attempt.

Also... if one of your objects contains "-" in its name, it may cause errors...

You'd have to change the line to look like this:

xfa.resolveNode("Page11-Section8-ExternalReviewsAndAudits").AUDITS.Q7b.rawValue = "NA";

OR

You could use "_" instead..:

Page11_Section8_ExternalReviewsAndAudits.AUDITS.Q7b.rawValue = "NA";

Avatar

Level 3

Your script was perfect and just saved me a bunch of time.  It wasn't working at first due to an error on my part.

Thanks again!!!!