Trying to have a Link or button URL change, based on value in a text field

New Here ,
Jul 09, 2020

Copy link to clipboard

Copied

Hello, 

 

I am currently trying to create a PDF of a schedule, where a user can select their desired program from a dropdown and the button will automatically have the corresponding link. 

 

I followed this tutorial to get the dropdown selection to effect a text field (successfully), but have no idea how to have the dropdown edit the link or button element, OR have the text field (based on the dropdown) effect the link/button. (I say link/button because I can use whichever works!)

 

Any assistance or links would be amazing, I've tried googling but no one else that I could find seems to want to do this. 

 

Thanks,

Sarah

Most Valuable Participant
Correct answer by try67 | Most Valuable Participant

Ah OK, got it. Let's say the text field is called "Text1". You can then use this code as the MouseUp event of the button field:

 

var t1 = this.getField("Text1").valueAsString;

if (t1=="") app.alert("The field is empty.");

else app.launchURL(t1);

TOPICS
Acrobat SDK and JavaScript, Edit and convert PDFs

Views

50

Likes

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

Trying to have a Link or button URL change, based on value in a text field

New Here ,
Jul 09, 2020

Copy link to clipboard

Copied

Hello, 

 

I am currently trying to create a PDF of a schedule, where a user can select their desired program from a dropdown and the button will automatically have the corresponding link. 

 

I followed this tutorial to get the dropdown selection to effect a text field (successfully), but have no idea how to have the dropdown edit the link or button element, OR have the text field (based on the dropdown) effect the link/button. (I say link/button because I can use whichever works!)

 

Any assistance or links would be amazing, I've tried googling but no one else that I could find seems to want to do this. 

 

Thanks,

Sarah

Most Valuable Participant
Correct answer by try67 | Most Valuable Participant

Ah OK, got it. Let's say the text field is called "Text1". You can then use this code as the MouseUp event of the button field:

 

var t1 = this.getField("Text1").valueAsString;

if (t1=="") app.alert("The field is empty.");

else app.launchURL(t1);

TOPICS
Acrobat SDK and JavaScript, Edit and convert PDFs

Views

51

Likes

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
Jul 09, 2020 0
Most Valuable Participant ,
Jul 09, 2020

Copy link to clipboard

Copied

Please be a bit more specific. Do you want to use the value of the text field in the URL? So if the text field says "Text1" the URL that the button will launch will be "http://www.google.com/q/Text1", for example?

Likes

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
Reply
Loading...
Jul 09, 2020 0
New Here ,
Jul 09, 2020

Copy link to clipboard

Copied

Sorry about that!
Basically, I want the text value appearing in the text field currently (its a URL) to be passed in. So, the value appearing as text in the text field is”www.google.com”, and I want that URL to be hyperlinked to a button.

Likes

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
Reply
Loading...
Jul 09, 2020 0
Most Valuable Participant ,
Jul 10, 2020

Copy link to clipboard

Copied

Ah OK, got it. Let's say the text field is called "Text1". You can then use this code as the MouseUp event of the button field:

 

var t1 = this.getField("Text1").valueAsString;

if (t1=="") app.alert("The field is empty.");

else app.launchURL(t1);

Likes

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
Reply
Loading...
Jul 10, 2020 1
New Here ,
Jul 10, 2020

Copy link to clipboard

Copied

You are a LIFE SAVER. 

Thank you so much! This worked perfectly. Is there a way to give kudos on here? 

Likes

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
Reply
Loading...
Jul 10, 2020 0
try67 LATEST
Most Valuable Participant ,
Jul 10, 2020

Copy link to clipboard

Copied

You're welcome!

 

Marking the answer as correct (and maybe liking it) is enough.

Likes

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
Reply
Loading...
Jul 10, 2020 0