Convert value to negative

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

Convert value to negative

Post by eayvl »

I need to convert to negative when adding an amount.

// Row Rendered event
function Row_Rendered() {

if (CurrentUserLevel() == 3) { 
	$(this).fields("pa_importe").value();
}

}

Thanks.

mobhar
User
Posts: 11726

Post by mobhar »

You cannot mix jQuery/Javascript code in Server Events section just like that.

You should use "Client-side Events" for such case. Please refer to the demo project, click on "orderdetails" table, go to "Fieds" setup -> "Edit Tag" pane, click on "Quantity" field, and then click on "Client side events" property to see the related Javascript code. Adjust it to your needs, for example by multiple the value by -1.


eayvl
User
Posts: 315

Post by eayvl »

I can convert it to negative, but I need to condition only for certain CurrentUser Level, there is a way to use:

Other idea? Thanks.
if (CurrentUserLevel() == 2) {

Just in case someone else needs it:

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

 	var Dif= $(this).fields("ph_importe").value(); 
var res= (Dif*-1); 
var res_1= res.toFixed(2) 
 	$(this).fields("ph_importe").value(res_1);
		
}

}


mobhar
User
Posts: 11726

Post by mobhar »

If you want to mix your PHP code into Javascript/jQuery code, then you may simply use "Startup Script" under "Client Scripts" -> "Table-Specific" -> "Add/Copy Page" or "Edit Page".


sangnandar
User
Posts: 980

Post by sangnandar »

This code is client-side.

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

var Dif= $(this).fields("ph_importe").value();
var res= (Dif*-1);
var res_1= res.toFixed(2)
$(this).fields("ph_importe").value(res_1);

}

CurrentUserLevel() is server-side variable.
So what you need to do is to pass this variable from server-side to client-side.
Here is how:

Page_Load()
ew_SetClientVar("myVar", CurrentUserLevel());

Then within your client-side code call this variable this way:
if (ewVar.myVar == 2) {bla..bla..bla..}


arbei
User
Posts: 9383

Post by arbei »

You can also use syntax as below in Startup Script.

<?php
if (CurrentUserLevel() == 2) {
?>
<Your client side script>
<?php
}
?>


Post Reply