Page 1 of 1
ToString() and str_replace
Posted: Fri Oct 28, 2016 1:06 am
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 ","?
Re: ToString() and str_replace
Posted: Fri Oct 28, 2016 11:16 am
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.
Re: ToString() and str_replace
Posted: Fri Oct 28, 2016 8:04 pm
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);
}
}
);
Re: ToString() and str_replace
Posted: Tue Apr 25, 2017 11:18 pm
by strustam
instead:
$row["rtot1_fatture_out"].value(st);
try this:
$row["rtot1_fatture_out"].value(ew_FormatNumber(st));