These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

Display missing required textbox name to user with Javascript

hina.pdfuser
Registered: Oct 28 2010
Posts: 26
Answered

I want to tell user which textboxes are not filled in a group of 100s of mandatory fields. So i created a test script. I have written following code for that textbox's properties using-> Format->Format Category=Custom.
 
As i m new to this work i dont know whether i have done correct or totally wrong. Do i need to do this on button click? If yes i m unable to find the location on button properties where i can write this script. Thats why i wrote on textbox properties.
______________________________________________
var msg = false;

if (this.getField("Initials").value == '')
{
var error = "Please fill Initials1";
msg = true;
}

if (msg){
app.alert(error);

}
______________________________________________
 
Pls help.

Thanks,
Hina

My Product Information:
Acrobat Pro 9.0, Windows
hina.pdfuser
Registered: Oct 28 2010
Posts: 26
Instead of format property, in actions tab, I added an Action also and created "On Blur" trigger and action as "Run a JavaScript". That also didn't work.

Thanks,
Hina

try67
Expert
Registered: Oct 30 2008
Posts: 2398
Accepted Answer
First of all, you should check whether the value is null.
Also, you are defining the error string in one scope and then use it in another. I don't think that'll work. Try this instead (I've added another alert just to make sure the script actually runs):

var msg = false;
var errorMsg = "";

if (this.getField("Initials").value==null || this.getField("Initials").value == "")
{
errorMsg = "Please fill Initials1";
msg = true;
}

if (msg){
app.alert(error);
} else app.alert("Everything is ok!");

- AcrobatUsers Community Expert - Contact me personally at try6767 [at] gmail [dot] com
Check out my custom-made scripts website: http://try67.blogspot.com

hina.pdfuser
Registered: Oct 28 2010
Posts: 26
Thanks a lot for help. Its now working fine and displaying msg also. Actually i needed this functioanlity on submit button. I have this button which redirects user to a website if all mandatory fields are fed by user.

i have done like this in properties of that button:
-Mouse Up
Run A javascript
Submit a form

Its working but it executes 2nd event in case of 1st is failed. I tried to use return to stop after 1st f^n but its not working.

Pls help.

Thanks,
Hina

try67
Expert
Registered: Oct 30 2008
Posts: 2398
You can't interact between the two events. You need to use the submitForm method from within the JavaScript event, and lose the Submit a Form event.

- AcrobatUsers Community Expert - Contact me personally at try6767 [at] gmail [dot] com
Check out my custom-made scripts website: http://try67.blogspot.com

hina.pdfuser
Registered: Oct 28 2010
Posts: 26
Can u pls highlight a little more. I am totally unable to get understanding.

Do u mean we need to delete or disable the second event. If yes how we can achieve this. Normal javascript is not working in acrobat.

Thanks,
Hina

try67
Expert
Registered: Oct 30 2008
Posts: 2398
Yes, you need to delete the second event.
Then you need to add a command to your script that submits the form if all is well.
The command you need to use is called submitForm and its a part of the Documnet object.
You can read more about it here:
http://livedocs.adobe.com/acrobat_sdk/9.1/Acrobat9_1_HTMLHelp/wwhelp/wwhimpl/common/html/wwhelp.htm?context=Acrobat9_HTMLHelp&file=JS_API_AcroJS.88.537.php

- AcrobatUsers Community Expert - Contact me personally at try6767 [at] gmail [dot] com
Check out my custom-made scripts website: http://try67.blogspot.com

hina.pdfuser
Registered: Oct 28 2010
Posts: 26
Thanks a lot for the link u provided me. Its now working as intended. U really helped me a lot.

Just for the sake of confirmation earlier i was submitting as HTML. If i write :

this.submitForm("http://localhost:1946/ProactivePMD/RequestPdfForm.aspx#FDF")

and specify nothing will it submit as HTML by default?

Thanks,
Hina

try67
Expert
Registered: Oct 30 2008
Posts: 2398
You're welcome.
And no, FDF is the default format.
If you want to submit it as HTML, do this:

this.submitForm({cURL: "http://localhost:1946/ProactivePMD/RequestPdfForm.aspx#FDF", cSubmitAs: "HTML"})

- AcrobatUsers Community Expert - Contact me personally at try6767 [at] gmail [dot] com
Check out my custom-made scripts website: http://try67.blogspot.com

hina.pdfuser
Registered: Oct 28 2010
Posts: 26
Ok. Done the same. Thanks a lot for helping on this thread. I hav another thread also on which i have a query.

http://acrobatusers.com/forum/javascript/display-message-if-required-fields-are-blank#comment-72178

Can u pls suggest a little on that also?

Thanks,
Hina