Highlighted

Couple of question

Explorer ,
Aug 18, 2020

Copy link to clipboard

Copied

1. How to use "else" without if?

example:

var sum1 = this.getField("field1").value;

var sum2 = this.getField("field2").value;

var total = sum1+sum2;

event.value = total;

else event.value = "";

 

2. In custom dialog box how to make "cancel" or "other" button do the same as "ok" button?

example:

 commit: function(dialog)
{
var data = dialog.store();
this.strName = data["usnm"];
},
butn: function(dialog){
this.strName = data["usnm"];
},

but it does nothing.

if I set it like this:

butn: function(dialog){
dialog.end("butn");

then it works, but I want it to do same as "ok" button.

 

TOPICS
Acrobat SDK and JavaScript, How to

Views

28

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

Couple of question

Explorer ,
Aug 18, 2020

Copy link to clipboard

Copied

1. How to use "else" without if?

example:

var sum1 = this.getField("field1").value;

var sum2 = this.getField("field2").value;

var total = sum1+sum2;

event.value = total;

else event.value = "";

 

2. In custom dialog box how to make "cancel" or "other" button do the same as "ok" button?

example:

 commit: function(dialog)
{
var data = dialog.store();
this.strName = data["usnm"];
},
butn: function(dialog){
this.strName = data["usnm"];
},

but it does nothing.

if I set it like this:

butn: function(dialog){
dialog.end("butn");

then it works, but I want it to do same as "ok" button.

 

TOPICS
Acrobat SDK and JavaScript, How to

Views

29

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
Aug 18, 2020 0
Most Valuable Participant ,
Aug 18, 2020

Copy link to clipboard

Copied

You can't, and your question makes no sense to someone who knows what else is for ... I think you're trying to copy a part of something you don't understand. Under what ACTUAL situation would you want to set event.value to "" ? Because I assume you don't want to do it every single time. So, what you need is an if.

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...
Aug 18, 2020 0
Explorer ,
Aug 18, 2020

Copy link to clipboard

Copied

I know what else is for, was just asking in my example above how would set without if, field value to "" if there is no calculation.

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...
Aug 18, 2020 0
Most Valuable Participant ,
Aug 18, 2020

Copy link to clipboard

Copied

But there IS a calculation. It's these three lines:

var sum1 = this.getField("field1").value;

var sum2 = this.getField("field2").value;

var total = sum1+sum2;

These will always happen. You need to define (because programmers need to be exact) just what you really mean by "no calculation". For example do you mean 

* field1 and field2 are both blank?

* field1 or field2, either one or both is blank?

* the result from adding up field1 and field2 is zero

* something else?

If you can answer this with accuracy, the code will probably be simple (and will have an if in it).

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...
Aug 18, 2020 0
Explorer ,
Aug 18, 2020

Copy link to clipboard

Copied

in this situation, field1 and field2 are both blank, I was asking can it be done without if.thanks for your answer.

any insight on my second question?

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...
Aug 18, 2020 0
Most Valuable Participant ,
Aug 18, 2020

Copy link to clipboard

Copied

That's a simple if. You see this as "not a calculation" but JavaScript does, because the line is there. It does what the rules of JavaScript state, and no more or less. In decades of programming I've often wanted it to read my mind... In pseudocode

 

if  ... field1 is blank and field 2 is blank ...

... then set the result to blank ...

else

... set the result to the sum of field 1 and field2 ...


Sorry, no insight into the second question.

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...
Aug 18, 2020 0