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

How can I create a textfield that checks the input value without the need of a button?

Participant ,
Apr 22, 2021 Apr 22, 2021

Copy link to clipboard

Copied

Hi everyone,

 

I´m trying to create a textfield to check the input (word) and pops up a message in case the answer is right.

The problem is: In ase the answer is wrong and the user mouseclick the textfield again, the message pops up again, before the field is cleared.

 

I´m using the following script in the Custom Keystroke Format section:


if(event.value == "on"){

app.alert ("Congratulations!", 3,0);

}

else if (event.value == "in"){

app.alert("Incorrect answer. Try again", 0,0);

}

else if (event.value == "at"){

app.alert("Incorrect answer. Try again", 0,0);

}

 

 

Thanks a lot in advance for your help!!

TOPICS
Create PDFs , How to , JavaScript , PDF forms

Views

576

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 ,
Apr 22, 2021 Apr 22, 2021

Copy link to clipboard

Copied

Use the validation event, instead.

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 ,
Apr 22, 2021 Apr 22, 2021

Copy link to clipboard

Copied

PS. You might want to consider using a generic "Incorrect answer" alert if the text is anything but "on", instead of specifying all possible wrong answers...

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
Participant ,
Apr 22, 2021 Apr 22, 2021

Copy link to clipboard

Copied

 

Thanks you very much! It worked fine.

Only now, I´m having problems clearing the fields programatically via a menu button.

An error message pops up for every textfield.

I´m using the following script:

 

var fields = new Array();

fields[0] = "Text25";
fields[1] = "Text26";
fields[2] = "Text27";
fields[3] = "Text28";
fields[4] = "Text29";
fields[5] = "Text30";
fields[6] = "Text31";
fields[7] = "Text32";
fields[8] = "Text33";
fields[9] = "Text34";

this.resetForm(fields);

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 ,
Apr 22, 2021 Apr 22, 2021

Copy link to clipboard

Copied

Use this code:

 

if (event.value) {
	if (event.value == "on") {
		app.alert ("Congratulations!", 3,0);
	} else app.alert("Incorrect answer. Try again", 0,0);
}

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
Participant ,
Apr 22, 2021 Apr 22, 2021

Copy link to clipboard

Copied

Thanks! It´s working now.

BUT, I still have another problem. Sorry!

 

I decided to include one last line, before the last closing brace, to clear the text field (as follows), in case the answer is wrong.

 

event.value = "";

 

But it´s not working properly, because now it is clearing even the right answers.

Is there a better position to include that line?

 

Thanks you very much in advance!!

 

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 ,
Apr 22, 2021 Apr 22, 2021

Copy link to clipboard

Copied

HI,

 

Just add it so the code looks like

if (event.value) {
	if (event.value == "on") {
		app.alert ("Congratulations!", 3,0);
	} else {
                app.alert("Incorrect answer. Try again", 0,0);
                event.rc = "";
       }
}

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 ,
Apr 22, 2021 Apr 22, 2021

Copy link to clipboard

Copied

No, it should be:

event.rc = false;

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
Participant ,
Apr 22, 2021 Apr 22, 2021

Copy link to clipboard

Copied

Everything is working fine now.

Thanks you very much!!

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
Participant ,
Apr 22, 2021 Apr 22, 2021

Copy link to clipboard

Copied

LATEST

Thank you very much, sir!

 

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