Copy link to clipboard
Copied
I have searched and tired several javascripts, but being a beginner in this area I must have forgotten something along the string.
I have a checkbox that if selected a sentence shows up. (I've named the checkbox and the text box, too)
Another checkbox, that if selected also a popup sentence and another exisiting filed must be required and filled out.
It worked. Whew
I changed the script
this.getField("CHG").display = (event.target.value=="Yes")?display.hidden : display.visible;
Thank you so much for your patience. There were more things I would like to have scripted in this form, but I must say that this simple little script has caused me a headache. THANK YOU, again.
Copy link to clipboard
Copied
You'll need to be more specific about the second bit, i.e., the other checkbox.
But just in general, there are two options.
1. Use the MouseUp on the checkbox to fill or delete the text box. This works when the text box has only one source of data, that being the single checkbox.
2. Use a calculation script on the text box. This works for when the text has several sources. such as several checkboxes.
What's your situation?
Copy link to clipboard
Copied
Hello Tom,
I am working a form and with request to include a drop down list selecting A, B, C, D. However, when selecting B an alert/text should pop up. Selected C a different alert and for D another alert. So now, I created a checkbox for each A, B, C, D and hoped to add a script to each checkbox with individual popup alerts/texts. I've named my checkboxes TTL CDC so they are not checkbox1, checkbox2,
I've tried others, but ended up with those two below. That do not seam to work.
f.setAction("MouseUp","app.alert('Change pricing on customer account - no JQ necessary!');");
if (event.target.value == "Yes")
app.alert("Message", 3);
I have been reviewing and customizing quite a few options, but some guidance would really help.
Thank you for your time.
Copy link to clipboard
Copied
First, the "setAction" function is only used scripts for creating document, never in a working PDF. So don't use it.
You're second script uses the correct form, it should be used on the MouseUp event of the checkbox.
if (event.target.value == "Yes") app.alert("Message", 3);
So exactly what is the issue?
Copy link to clipboard
Copied
Hi Tom,
I am not able to post, keep getting this msg without any highlights. No HTML in body.
Copy link to clipboard
Copied
Hi Tom,
1. I created a chebox in the form called CDCBuys, that when you check it it should pop up and alert stating: Change pricing on customer account - no JC necessary!
Currently, I have the scrip below for this scenario, but nothing happens when I click the checkbox.
Upper Menu
Select Trigger: MouseUp / Run a JavaScript
Actions
-MouseUp
Run a JavaScript
if (event.target.value=="Yes")
app.alert("Message",3);
2. The other scenario is that when a differnt checkbox named "Other" is selected, a textbos should aprear to enter text.
I hope this explains it better. If you wish, I can privately send the form for review.
Thank you,
Beate
Copy link to clipboard
Copied
1. Is the export value of the checkbox "Yes"? If its not, then this scirpt won't work.
2. Are there any errors reported in the Console Window?
You'll find a tutorial on the Console here:
https://www.pdfscripting.com/public/Free_Videos.cfm#JSIntro
Copy link to clipboard
Copied
Hi
Thank you. I totally missed that step from all the tutorials I've researched. That's why the Yes didn't make much sence to me.
I appreciate your continued suppoert and the tutorial, too.
All my Best,
Beate
Copy link to clipboard
Copied
Hi again,
I didn't see anything on item 2 from email above, but the message pop up is fantastic.
What steps do I need to follow to have a box when selected make a field apear to enter text and stay visable?
Thank you,
Beate
Copy link to clipboard
Copied
Just add onto your existing code, either before or after the alert.
Here's an article on this topic:
https://acrobatusers.com/tutorials/show_hide_fields/
Copy link to clipboard
Copied
Thank you! Your advice has made an huge impact on the functional success of my form. Plus, I've learned a lot, too.
I greatly appreciate it.
Beate
Copy link to clipboard
Copied
Hello again,
I looked over the great informational links you sent. Thank you. I've applied working in the console now. However, I don't seam to get any debugging suggestions only the lovely undefined.
I have been sucessful to hiding a checkbox ("CHG") when checkbox ("New") is selected, but I can get it back to a visable presence if the ("New") is unselected. I don't know if it matters, but the ("CHG") checkbox has the script running we've talked at in the beginning. so it is mouse up, JS.
Do you have any suggestions?
I've been finding lots of other tutorials, but (as a total beginner in this field) customizing those scripts leaves me resultless.
Thank you so much for your time.
Beate
Copy link to clipboard
Copied
Please post the code for the Mouse Up script in the "New" checkbox. The CHG code shouldn't matter unless it is affecting it's own visibility.
Copy link to clipboard
Copied
Here is one of the last ones. I overwrote the first one that half the job.
//Document-level function
function cbControl(){
//Get a reference to each check box
var f1 = getField("New");
var f2 = getField("CHG");
//hide CHG if New was selected
if(event.target===f1||event.target===
f2.value = "off";
return;
}
//Uncheck New
if(event.target===f1event.target===
f2.value = "Yes"
}
}
var visable = event.target.isBoxChecked("New")(1)display.hidden:display.visable;
this.getField("CHG").display=display.hidden;
}
else
(event.target.isBoxChecked("New")(0)
Display.hidden:display.visable
{
this.getField("CHG').display=display.visable
}
Copy link to clipboard
Copied
As the code is shown in the post, it could not possibly do anything. There are many many syntax errors.
Is this code correct, or was there an issue pasting the code to this message?
It also looks massively over complex for what it is supposed todo.
And you didn't say exactly where the function is called, please state this everytime you post code.
Copy link to clipboard
Copied
Thank you for your patience with me. I figured as much. I've copied that from several sites. I wish I hadn't wrote over the first JS that worked to hid, but not made the CHG button visable again.
I have tried this one, but it didn't bring back the checkbox (CHG) after the checkbox (New) is deselected.
Function= if checkbox("New") is selected, then hide checkbox("CHG"). else, if checkbox("New") is deselcted, unhide checkbox ("CHG).
this.getField("CHG").display = (this.getField("New").value=="Off") ? display.hidden : display.visible;
Is this what you referred to add?
Thank you,
Beate
Copy link to clipboard
Copied
That is the correct script, but you didn't say where this script is located.
If it is in the MouseUp for the "New" checkbox, then this code will work;
this.getField("CHG").display = (event.target.value=="Off")?display.hidden : display.visible;
Copy link to clipboard
Copied
Sorry, I missed that. Yes, it is in the Mouse up in the ("New") checkbox.
I tried the script it dues the hidden/visible display for ("CHG"), except for the opposite of what it should be. when New is selected CHG to be hidden. otherwise CHG visiable.
this.getField("CHG").display = (event.target.value=="Off")?display.hidden : display.visible;
I tried to replace "off" with yes and reversed the hidden visible. No luck.
So close!
Thank you,
Beate
Copy link to clipboard
Copied
That is very strange. I tested the script and it works fine. The unchecked value of any checkbox or radio button group is "Off", verbatim. Which means that display gets hidden. If you are going to change the condition, then make sure it is set to the exact export value.
If the oposite is happening of what this code is indicating, and you changed the condition and that didn't change anything. Then it is likely the visibility is being controlled by another script.
Is there any other code in your form that could be affecting the visibility of the checkbox? Make sure all other code is removed.
Copy link to clipboard
Copied
That makes sense.
I've attached a pix of the check boxes.
the CHG checkbox has a mouse up JS that makes a field appear to enter the reasons. (highlighted)
the goal is not to be able to have both checkboxes checked at the same time.
Copy link to clipboard
Copied
But did you check for scripts that affect the visibility of the "CHG" field? Use the "Edit all scripts" option to search for all scripts that reference "CHG", and delete them. Except of couse for the MouseUp on "New".
Copy link to clipboard
Copied
Hi again,
I've attached screenshots of the file and what happens when checkbox ("New") is checked and unchecked.
Copy link to clipboard
Copied
It worked. Whew
I changed the script
this.getField("CHG").display = (event.target.value=="Yes")?display.hidden : display.visible;
Thank you so much for your patience. There were more things I would like to have scripted in this form, but I must say that this simple little script has caused me a headache. THANK YOU, again.