[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Adding 2 text fields in a database form (with Caspio Bridge)

Posted on 2011-05-05
3
Medium Priority
?
970 Views
Last Modified: 2012-05-11
<SCRIPT LANGUAGE="JavaScript">

function concatenate()
{
var Invoice1Total = document.getElementById("EditRecordInvoice1Total").value;
var Invoice2Total = document.getElementById("EditRecordInvoice2Total").value;
var Invoice3Total = document.getElementById("EditRecordInvoice3Total").value;

var NetCost = Invoice1Total + Invoice2Total + Invoice3Total;

document.getElementById("EditRecordNetCost").value = netcost;

}

document.getElementById("netcost").onblur=concatenate;
</SCRIPT>
0
Comment
Question by:RickardP_GSI
  • 3
3 Comments
 
LVL 82

Assisted Solution

by:hielo
hielo earned 2000 total points
ID: 35708509
try:
<SCRIPT LANGUAGE="JavaScript">

function concatenate()
{
	var Invoice1Total = parseInt(document.getElementById("EditRecordInvoice1Total").value,10);
	var Invoice2Total = parseInt(document.getElementById("EditRecordInvoice2Total").value,10);
	var Invoice3Total = parseInt(document.getElementById("EditRecordInvoice3Total").value,10);

	var NetCost = (isNaN(Invoice1Total)?0:1*Invoice1Total) + (isNaN(Invoice2Total)?0:1*Invoice2Total) + (isNaN(Invoice3Total)?0:1*Invoice3Total);

	document.getElementById("EditRecordNetCost").value = NetCost;
return NetCost;
}
window.onload=function(){
	document.getElementById("netcost").onblur=concatenate;
}
</SCRIPT>

Open in new window

0
 
LVL 82

Accepted Solution

by:
hielo earned 2000 total points
ID: 35708532
The previous post ADDS the values of the fields. If you are trying to actually "concatenate", then try:
<SCRIPT LANGUAGE="JavaScript">

function concatenate()
{
	var Invoice1Total = document.getElementById("EditRecordInvoice1Total").value;
	var Invoice2Total = document.getElementById("EditRecordInvoice2Total").value;
	var Invoice3Total = document.getElementById("EditRecordInvoice3Total").value;

	var NetCost = Invoice1Total + Invoice2Total + Invoice3Total;

	document.getElementById("EditRecordNetCost").value = NetCost;
return NetCost;
}
window.onload=function(){
	document.getElementById("netcost").onblur=concatenate;
}
</SCRIPT>

Open in new window

0
 
LVL 82

Assisted Solution

by:hielo
hielo earned 2000 total points
ID: 35708550
On the "concatenation" version:
>>      var NetCost = Invoice1Total + Invoice2Total + Invoice3Total;

should be:
var NetCost = String(Invoice1Total) + String(Invoice2Total) + String(Invoice3Total);
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
A quick Powershell script I wrote to find old program installations and check versions of a specific file across the network.
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
Suggested Courses
Course of the Month19 days, 17 hours left to enroll

872 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question