I will try to word this the best that I can. Let's say i have two dropdown menus, 1st menu contains choices 1-5, the 2nd menu: choices 6-10. If choice 1 is selected on the first drop down, textboxAlert will auto-populate with the sentence "Display sentence 1". If choice 2 is selected, "Display Sentence 2" is displayed, and the previous sentence is erased. Onto the second dropdown menu, If i choose choice 6, "Display sentence 6" is shown in textboxAlert, along with the sentence from the first dropdown. So, for example's sake, I choose choice 1 on the first dropdown and choice 6 on the second dropdown.
textboxAlert will read:
Display Sentence 1
Display Sentence 6
Now here is where it gets tricky, and where my question arises. I currently am using VARs to add the sentence, so textboxAlert = oldV + "/n Display Sentence 1", where oldV stores the text in textboxReminder right before the sentence is added. I already figured out the issue of adding duplicate sentences, so no worries on that problem. Let's say I go back to the first dropdown menu, and now select choice 3. textboxAlert will now read:
Display Sentence 1
Display Sentence 6
Display Sentence 3
However, I would like it to read:
Display Sentence 3
Display Sentence 6
Because I am adding sentences to the same textbox, I cannot erase just the first line of text and replace it with the sentence I would like, without compromising the second line of text. Any thoughts on how I can accomplish this? Is there any way to search for a string of text within a textbox, and delete that string? Thanks, let me know if this needs more clarification.
Solved! Go to Solution.
Views
Replies
Total Likes
I put together a sample file for you on this..
https://acrobat.com/#d=sra7qHRg4mzrn0VM4sm*VQ
In this PDF, I created a Script Object which will take the selected value from the drop down and return the text that needs to be displayed in the text field.
If the selected value is not between 1-5 or 6-10 then the function will return empty string.
Let me know if you need to any clarification..
Thanks
Srini
Views
Replies
Total Likes
From your post I understand that you are adding a new line chanracter ("\n") in the code while appending the text to the Textfield.
You can use the split function of the javaScript to retrieve each line form the text field. this way you get the control on each line from the text field.
Below is the sample code for your reference.
TextField1 in my sample is a multiline textbox.
var oList = TextField1.rawValue.split("\n");
for(i=0;i<oList.length;i++){
xfa.host.messageBox("" + oList[i]);
}
Thanks
Srini
Yea, I guess the split function is what I am looking for. I'm not exactly sure where to utilize it in my code, so here is the sample code that I am using, maybe you can help me from there:
Change Event for the first dropdown:
if(xfa.event.newText == "Choice 1"){
var oldV = txtVar.rawValue
txtReminder.rawValue = oldV + "\n Display Sentence 1"
txtVar2.rawValue = txtReminder.rawValue;
}
else if(xfa.event.newText == "Choice 2"){
var oldV = txtVar.rawValue
txtReminder.rawValue = oldV + "\n Display Sentence 2"
txtVar2.rawValue = txtReminder.rawValue;
}
else if(xfa.event.newText == "Choice 3"){
var oldV = txtVar.rawValue
txtReminder.rawValue = oldV + "\n Display Sentence 3"
txtVar2.rawValue = txtReminder.rawValue;
}
else if(xfa.event.newText == "Choice 4"){
var oldV = txtVar.rawValue
txtReminder.rawValue = oldV + "\n Display Sentence 4"
txtVar2.rawValue = txtReminder.rawValue;
}
else if(xfa.event.newText == "Choice 5"){
var oldV = txtVar.rawValue
txtReminder.rawValue = oldV + "\n Display Sentence 6"
txtVar2.rawValue = txtReminder.rawValue;
}
else{
var oldV = txtVar.rawValue
txtReminder.rawValue = oldV;
Change Event for the second dropdown:
if(xfa.event.newText == "Choice 6" {
var oldV2 = txtVar2.rawValue
txtReminder.rawValue = oldV2 + "\n Display Choice 6"
txtVar.rawValue = txtReminder.rawValue;
var oldV = txtVar.rawValue
}
else {
var oldV2 = txtVar2.rawValue
txtReminder.rawValue = oldV2
}
I scaled down the code to make this simpler. I tried to use the split function but had no luck. Perhaps I am using the code incorrectly, or inserting it in the wrong place? Please advise, thanks!
Views
Replies
Total Likes
Have you tried writing the values to an array and putting them in the message box? I put this on the validate event of a hidden text field. dd1 and dd2 are the names I used for my drop down lists.
var myStrArray = new Array();
myStrArray[0] = dd1.rawValue;
myStrArray[1] = dd2.rawValue;
xfa.host.messageBox((myStrArray[0] + "\n" + myStrArray[1]), "Values", 3);
The only drawback with this is that it outputs null for blank values but you can easily put in a null test if that's a problem.
I put together a sample file for you on this..
https://acrobat.com/#d=sra7qHRg4mzrn0VM4sm*VQ
In this PDF, I created a Script Object which will take the selected value from the drop down and return the text that needs to be displayed in the text field.
If the selected value is not between 1-5 or 6-10 then the function will return empty string.
Let me know if you need to any clarification..
Thanks
Srini
Views
Replies
Total Likes
Awesome, this looks like very helpful. Thanks a bunch. I'll take a more detailed look and let you know if I have any questions. Great job, thanks again!
Views
Replies
Total Likes