• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

looking for a java script to show a sentence when a checkbox is selected.

Explorer ,
Jan 22, 2020 Jan 22, 2020

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. 

 

TOPICS
Acrobat SDK and JavaScript

Views

2.6K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Explorer , Jan 30, 2020 Jan 30, 2020

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. 

Votes

Translate

Translate
Community Expert ,
Jan 22, 2020 Jan 22, 2020

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?

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jan 22, 2020 Jan 22, 2020

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 22, 2020 Jan 22, 2020

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?

 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jan 23, 2020 Jan 23, 2020

Copy link to clipboard

Copied

Hi Tom,

I am not able to post, keep getting this msg without any highlights. No HTML in body.

 
 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jan 23, 2020 Jan 23, 2020

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 23, 2020 Jan 23, 2020

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

 

 

 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jan 23, 2020 Jan 23, 2020

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jan 23, 2020 Jan 23, 2020

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 23, 2020 Jan 23, 2020

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/

 

 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jan 24, 2020 Jan 24, 2020

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jan 29, 2020 Jan 29, 2020

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 29, 2020 Jan 29, 2020

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. 

 

 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jan 29, 2020 Jan 29, 2020

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
}

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 29, 2020 Jan 29, 2020

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.

 

 

 

 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jan 30, 2020 Jan 30, 2020

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 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 30, 2020 Jan 30, 2020

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;
Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jan 30, 2020 Jan 30, 2020

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

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 30, 2020 Jan 30, 2020

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.  

 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jan 30, 2020 Jan 30, 2020

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.

 

chckbox.JPG

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 30, 2020 Jan 30, 2020

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". 

 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jan 30, 2020 Jan 30, 2020

Copy link to clipboard

Copied

Hi again,

I've attached screenshots of the file and what happens when checkbox ("New") is checked and unchecked.new sel.jpgnewblank chg blank.png

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jan 30, 2020 Jan 30, 2020

Copy link to clipboard

Copied

LATEST

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. 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines