The if Statement conditional in Client side events

This public forum is for user-to-user discussions of PHPMaker. Note that this is not support forum.
Post Reply
eayvl
User
Posts: 315

The if Statement conditional in Client side events

Post by eayvl »

Hi, i have this code that works and works more or less:

I have 2 fields:
"Pa_mes" (in this field I have the code)
"Pa_diario"

  • If you capture in field "pa_mes" 400 in the field "pa_diario" add 410 and it is incorrect should be 110, because the amount is less than 1000.

  • If you capture in field "pa_mes" 4500 in the field "pa_diario" add 410 and it is correct, because the quantity is greater than 4000.

  • When I delete the quantity from the "pa_mes" field in the field "pa_diario", the quantity is not eliminated, why? In advance thank you very much.

{ // keys = event types, values = handler functions
"change": function(e) {
if (this.value == "") {
$(this).fields("pa_diario").value(); // Set value
} else if (this.value < "1000") {
$(this).fields("pa_diario").value("100"); // Set value
} else if (this.value < "2000") {
$(this).fields("pa_diario").value("200"); // Set value
} else if (this.value < "3000") {
$(this).fields("pa_diario").value("300"); // Set value
} else if (this.value < "4000") {
$(this).fields("pa_diario").value("400"); // Set value
}
}
}


arbei
User
Posts: 9373

Post by arbei »

} else if (this.value < "1000") {

In about condition, you should compare the numeric value but not string. Google "JavaScript parseInt".


eayvl
User
Posts: 315

Post by eayvl »

Hi,

It works fine, but the value that is in the field "pa_diario" is not registered in the table.

{ // keys = event types, values = handler functions
"change": function(e) {
// Your code

if ($(this).fields("pa_mes").value() < parseInt("1")) {
 		$(this).fields("pa_diario").value("0"); // Set value
 			
 	} else if ($(this).fields("pa_mes").value() < parseInt("1000")) {
     	$(this).fields("pa_diario").value("100"); // Set value
     		
     } else if ($(this).fields("pa_mes").value() < parseInt("2000")) {
     	$(this).fields("pa_diario").value("200"); // Set value
     		
     } else if ($(this).fields("pa_mes").value() < parseInt("3000")) {
     	$(this).fields("pa_diario").value("300"); // Set value
     		
     } else if ($(this).fields("pa_mes").value() < parseInt("4000")) {
     	$(this).fields("pa_diario").value("400"); // Set value         		
    }
}		

}

The Google recommendation "JavaScript parseInt" thanks.


eayvl
User
Posts: 315

Post by eayvl »

When I use "add" the data of the field "pa_diario" in the table is not registered, but when I use "edit" yes, this is registers.

$(this).fields("pa_diario").value("400"); // Set value

why?


Post Reply