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.
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.
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.
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.
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).
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?
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.