2012-02-03 74 views
1

我有一个基于数据库值填充字段的更新表单。表单包含计算,因此我将该字段的值设置为数据库值,但添加了onChange以允许表单在更新后重新计算数字。我确信这肯定是一个难题,但我不知道如何解决它。这是我做的一个例子:onChange在更新表单上不能正常工作

<td><input type="text" Name="price" id="price" size="8" class="TextBox" value="#price_value#" onFocus="this.className='TextBoxSelected';select()" onBlur="this.className='TextBox'" onChange="calculate();" /></td> 


    function getFldValue(fldValue) { 
     return isNaN(fldValue) ? 0 : parseFloat(fldValue); 
    } 
    function calculate() { 
     var property_SPrice = getFldValue($('#property_SPrice').val()); 
     var price = getFldValue($('#price').val()); 
     $('#price').val(property_SPrice + 0); 

但是;当property_SPrice被改变时,它只是将价格清零,所以我不确定我需要在这里更改以使其正常工作。顺便说一句,我是新来的这个,在此先感谢您的帮助。

+0

#property_SPrice定义在哪里,我没有看到具有该ID的元素?它如何得到更新? – 2012-02-03 16:52:19

+0

这里是:​​*已售出的价格:$ user1171786 2012-02-03 16:59:12

+0

propert_SPrice必须定义为ID值不只是名称 – 2012-02-03 18:48:47

回答

1

this line:return isNaN(fldValue)? 0:parseFloat(fldValue);

试试这个

var property_SPrice = getFldValue(Number($('#property_SPrice').val())); 

或:

var property_SPrice = getFldValue(parseInt($('#property_SPrice').val())); 

$('#property_SPrice').val() has to be a number/integer not a string version of a number/integer i.e. 9273 not '9273' 

尝试typeOf $('#property_SPrice').val()console.log,看看它是

+0

谢谢,我做了更改,但不幸的是它没有解决问题。我认为这可能是为什么,这是一个由其他人创建的表单,它们包括从数据库获取值:' user1171786 2012-02-03 17:12:11

+0

$('#property_SPrice').val()的值是多少? – zero 2012-02-03 17:16:32

+0

换句话说,进入该字段的数据库的价值是多少(即价格23.99美元或整数88或整数64.256)? – zero 2012-02-03 17:27:02

0

propert_SPrice已被定义为ID值不只是名称