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

If field is empty then run a script:

bensimmons99
Registered: Jun 2 2010
Posts: 28
Answered

I have this Document level JS that runs when the document is opened.

var t = this.getField("DELIVER_TO"); // the target field
var cResponse = app.response({
cQuestion: "What is the ITT EMAIL address for the Deliver To Individual?",
cTitle: "Deliver to eMail address"});

if (cResponse == null){
// if Cancel is selected
app.alert ("Cancel this Purchase Request?");
cResponse = 0;
}else{
// places the data from the dialog to the target field
t.value = cResponse;
}

How do I make it run ONLY if there is nothing in the field?

THX

Ben

gkaiseril
Expert
Registered: Feb 23 2006
Posts: 4307
You can use the 'while()' statement to keep asking the question until the cancellation is confirmed or a value is entered. Also 'null' is a string.
var t = this.getField("DELIVER_TO"); // the target fieldvar cResponse;while(t.value == '' | t.value == 'null') {t.value = app.response({cQuestion: "What is the ITT EMAIL address for the Deliver To Individual?",cTitle: "Deliver to eMail address"});// null response if (t.value == 'null'){// ask for cancel choicecResponse = app.alert ({cMsg: "Confirm canceling this Purchase Request?", nIcon: 2, nType: 3, cTitle:'Confirm Cancellation'});// yes end loopif(cResponse == 4) {break; // force exit}} // end null response   } // end while t null or empty// remove null string if presentif(t.value == 'null') t.value = '';

This code and not reside in the referenced form field.

George Kaiser