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

Submit form conditionally based on radio button selection

New Here ,
Apr 15, 2021 Apr 15, 2021

Hello,

I am trying to write a script that will submit a form to a specific email address based on which radio button is selected. I found some code for an if/else if setup, but it isn't working. I have three choices in my buttons, but it's only picking up the first email address and ignoring the variable. Also, I am trying to use cSubmitAs in order to submit as a PDF but it just appended cSubmitAs to the end of the email address, so I took it out (so bonus points to the person who helps there). Here's what I have so far:

 

var nCounty = this.getField("County").value;
if( nCounty = "County1" ) event.value = this.submitForm(
"mailto:jsmith@corpnet.org"
);
else if( nCounty = "County2" ) event.value = this.submitForm(
"mailto:joe.smith@corpcom.org"
);
else if( nCounty = "County3" ) event.value = this.submitForm(
"mailto:jane@corporg.org"

);

 

I'm trying to teach myself code but am having trouble understanding some of the basics because I can only find information in small chunks.

Any help would be amazing! Thanks ;0)

Meghan

TOPICS
Create PDFs , Edit and convert PDFs , JavaScript , PDF forms
922
Translate
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
1 ACCEPTED SOLUTION
Community Expert ,
Apr 15, 2021 Apr 15, 2021

1. For comparisons you must use "==" or "===", not "=". That's used to assign a value.

2. The submitForm method doesn't return a value, so drop the event.value = ... parts from your code.

3. If you want to specify parameters you have to name them (or specify them all, in the order described in the reference).

 

So change this, for example:

 

if( nCounty = "County1" ) event.value = this.submitForm(
"mailto:jsmith@corpnet.org"
);

 

To:

 

if ( nCounty == "County1" )

this.submitForm({cURL: "mailto:jsmith@corpnet.org", cSubmitAs: "PDF"});

View solution in original post

Translate
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 ,
Apr 15, 2021 Apr 15, 2021

1. For comparisons you must use "==" or "===", not "=". That's used to assign a value.

2. The submitForm method doesn't return a value, so drop the event.value = ... parts from your code.

3. If you want to specify parameters you have to name them (or specify them all, in the order described in the reference).

 

So change this, for example:

 

if( nCounty = "County1" ) event.value = this.submitForm(
"mailto:jsmith@corpnet.org"
);

 

To:

 

if ( nCounty == "County1" )

this.submitForm({cURL: "mailto:jsmith@corpnet.org", cSubmitAs: "PDF"});

Translate
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
New Here ,
Apr 15, 2021 Apr 15, 2021
LATEST

THANK YOU ONE MILLION TRILLION TIMES!!!!!!!

It worked ;0)

Translate
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