ToString() and str_replace

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

ToString() and str_replace

Post by alessio »

Hi, i have this:

// Table 'fatture_out' Field 't_iva1_fatture_out'
$('[data-table=fatture_out][data-field=x_t_iva1_fatture_out]').on(
	{ // keys = event types, values = handler functions
	     "blur": function(e) {
	         var $row = $(this).fields();
			         var $row = $(this).fields();
			         var st = $row["qn1_fatture_out"].toNumber() * $row["iu1_fatture_out"].toNumber();
			         $row["rtot1_fatture_out"].value(st);
	var dr = (($row["qn1_fatture_out"].toNumber() * $row["iu1_fatture_out"].toNumber()) / (1 + ($row["iva1_fatture_out"].value() / 100)));
			         $row["t_imp1_fatture_out"].value(dr);
	var mr = ((($row["t_imp1_fatture_out"].value()) * ($row["iva1_fatture_out"].value())) / 100);
	var mr = mr.value.toString()	
					$row["t_iva1_fatture_out"].value(mr); 
	     }
	 }

How to convert "$row["t_iva1_fatture_out"].value(mr); " in string, and replace the "." to ","?


arbei
User
Posts: 9286

Post by arbei »

The syntax is str.replace("<search string>","<replace string>");
And you should replace the text before you assign it to the control.

For example:
var mr = mr.value.toString();
mr = mr.replace("<search string>","<replace string>");
$row["t_iva1_fatture_out"].value(mr);

Search "JavaScript replace" in Google for more information.


alessio
User
Posts: 27

Post by alessio »

I can write better, but meanwhile the solution is to use json:

$('[data-table=fatture_out][data-field=x_descrizione1_fatture_out]').on(
	{ "change": function(e)
	{
	var $row = $(this).fields();
	var st = $row["qn1_fatture_out"].toNumber() * $row["iu1_fatture_out"].toNumber();
	$row["rtot1_fatture_out"].value(st);
	var dr = (($row["qn1_fatture_out"].toNumber() * $row["iu1_fatture_out"].toNumber()) / (1 + ($row["iva1_fatture_out"].value() / 100)));
	$row["t_imp1_fatture_out"].value(dr);
	var mr = ( (($row["t_imp1_fatture_out"].value()) * ($row["iva1_fatture_out"].value())) / 100);
	mr = JSON.stringify(new String(mr));
	mr = mr.replace('.',',');	
	mr = mr.replace('"','');			
	mr = mr.replace('"','');
	$row["t_iva1_fatture_out"].value(mr);
	}
	}
);

strustam
User
Posts: 33
Location: Tajikistan

Post by strustam »

instead:
$row["rtot1_fatture_out"].value(st);

try this:
$row["rtot1_fatture_out"].value(ew_FormatNumber(st));


Post Reply