价格计算器使用Javascript

时间:2011-05-23 20:32:15

标签: javascript

我正在尝试重新创建此页面http://psdtowp.com/order-now,但出于其他目的, 我是JS的新手,所以我要做的是有一个带有未定义值的变量列表,然后我想让我的输入字段onkeyup将用值填充变量,这可能吗?

目前我的代码是......

/////////////////////////////////////////////////////////////////////

// Variables

// Content/SLA
var ContentMinutes = '';
var ContentMinutesSelector; // Switch Case
var ServiceLevel = '';
var NoOfFrames = '';

// Render Time (Hairier the Better)
var AvgFrameRenderTime = '';
var AvgFrameRenderTimeSelector; // Switch Case
var CoresInTest = '';

// Cost Estimate
var CostEstimate = '';

// Other
var EstimatedCoreHours = '';


/////////////////////////////////////////////////////////////////////

//  Functions

function CalculateEstimate() {
var EstimatedTotal = EstimatedCoreHours * ServiceLevel;     
document.getElementById("PriceEstimate").innerHTML=EstimatedTotal.toFixed(2);
 }

我的onkeyup计算在我的源代码中只有这个JS无效...

/////////////////////////////////////////////////////////////////////

// Variables

// Content/SLA
var ContentMinutes = '';
var ContentMinutesSelector; // Switch Case
var ServiceLevel = 5;
var NoOfFrames = '';

// Render Time (Hairier the Better)
var AvgFrameRenderTime = '';
var AvgFrameRenderTimeSelector; // Switch Case
var CoresInTest = '';

// Cost Estimate
var CostEstimate = ServiceLevel * EstimatedCoreHours;

// Other
var EstimatedCoreHours = 10;


/////////////////////////////////////////////////////////////////////

//  Functions

 function CalculateEstimate() { 
document.getElementById("PriceEstimate").innerHTML=CostEstimate.toFixed(2);
}

现在正在返回NaN

NVM,似乎我的变量需要在乘法之前设置,我没有意识到JS逐行读取它......

1 个答案:

答案 0 :(得分:0)

您只需要在输入中添加onkeyup="CalculateEstimate();" ...就像......

<input type='text' name='box1' onkeyup='CalculateEstimate();' />

Here is an example只添加了两个方框。