添加2个文本框的内容 [英] Add contents of 2 text box's

查看:67
本文介绍了添加2个文本框的内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是的,好的,我已经设计了一个表格,它会在

a文本框中显示价格(22.34),另一个价格在另一个文本框中......我也有一个空白

文本框...现在我想将两个价格加在一起,得到一个总额为

的bloank文本框..

我得到了这个关闭一个网站的示例..但它不显示

十进制数,它只显示整数


请帮助


var number1 = parseInt(document.forms [0] .CasesSellingPrice.value);

var number2 = parseInt(document.forms [0] .AccessoriesSellingPrice.value);

document.forms [0] .total.value = number1 + number2;

Right, ok, well I have designed a form that will display a price (22.34) in
a text box, and another price in the other text box... I also have a blank
text box... Now I want to add both the prices together and get a total in
the bloank textbox..
I got this example off a website sumwhere.. But it does not display the
decimal number, it only displays the whole number

PLEASE HELP

var number1 = parseInt(document.forms[0].CasesSellingPrice.value);
var number2 = parseInt(document.forms[0].AccessoriesSellingPrice.value);
document.forms[0].total.value = number1 + number2;

推荐答案

Phill Long写道:
Phill Long wrote:
是的,好的,我已经设计了一个表格,在一个文本框中显示价格(22.34),在另一个文本框中显示另一个价格......我也有一个空白
文本框...现在我要添加两个t他把价格放在一起并得到一个总数在
的bloank文本框..
我在一个网站上得到了这个例子。但它没有显示
十进制数,它只显示整数

请帮助

var number1 = parseInt(document.forms [0] .CasesSellingPrice.value);
var number2 = parseInt(document.forms [0] .AccessoriesSellingPrice.value);
document.forms [0] .total.value = number1 + number2;
Right, ok, well I have designed a form that will display a price (22.34) in
a text box, and another price in the other text box... I also have a blank
text box... Now I want to add both the prices together and get a total in
the bloank textbox..
I got this example off a website sumwhere.. But it does not display the
decimal number, it only displays the whole number

PLEASE HELP

var number1 = parseInt(document.forms[0].CasesSellingPrice.value);
var number2 = parseInt(document.forms[0].AccessoriesSellingPrice.value);
document.forms[0].total.value = number1 + number2;




阅读常见问题解答。全部,但特别是

http:// www .jibbering.com / faq / #FAQ4_21


var number1 = + document.forms [0] .CasesSellingPrice.value;

var number2 = + document.forms [0] .AccessoriesSellingPrice.value;

document.forms [0] .total.value = number1 + number2;


And,为什么你使用表单元素的混合访问器?尝试

保持统一:


var number1 = + document.forms [0] .elements [''CasesSellingPrice'']。value;

var number2 = + document.forms [0] .elements [''AccessoriesSellingPrice'']。value;

document.forms [0] .elements [''total'' ] .value = number1 + number2;


更好,但用表格名称/ id替换0会更好。


- -

兰迪

机会有利于准备好的心灵

comp.lang.javascript常见问题 - http://jibbering.com/faq/



Read the FAQ. All of it, but especially

http://www.jibbering.com/faq/#FAQ4_21

var number1 = +document.forms[0].CasesSellingPrice.value;
var number2 = +document.forms[0].AccessoriesSellingPrice.value;
document.forms[0].total.value = number1 + number2;

And, why are you using mixed accessors for the form elements? Try to
keep it uniform:

var number1 = +document.forms[0].elements[''CasesSellingPrice''].value;
var number2 = +document.forms[0].elements[''AccessoriesSellingPrice''].value;
document.forms[0].elements[''total''].value = number1 + number2;

Is better but replacing the 0 with the forms name/id would be even better.

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/


Phill Long写道:
Phill Long wrote:
对,好吧,我设计了一个表格,在一个文本框中显示价格(22.34),在另一个文本框中显示另一个价格。 ..我还有一个空白的
文本框...现在我想将两个价格加在一起,并在
的bloank文本框中得到一个...
我得到了是一个网站总和的例子..但它没有显示
十进制数,它只显示整数

请帮助

var number1 = parseInt( document.forms [0] .CasesSellingPrice.value);
var number2 = parseInt(document.forms [0] .AccessoriesSellingPrice.value);
document.forms [0] .total.value = number1 + number2;
Right, ok, well I have designed a form that will display a price (22.34) in
a text box, and another price in the other text box... I also have a blank
text box... Now I want to add both the prices together and get a total in
the bloank textbox..
I got this example off a website sumwhere.. But it does not display the
decimal number, it only displays the whole number

PLEASE HELP

var number1 = parseInt(document.forms[0].CasesSellingPrice.value);
var number2 = parseInt(document.forms[0].AccessoriesSellingPrice.value);
document.forms[0].total.value = number1 + number2;



此链接可能有所帮助:
http://www.aptools.com/javascript/


Jerry Park写道:
Jerry Park wrote:
Phill Long写道:
Phill Long wrote:
好吧,好吧,我已经设计了一个表格,在一个文本框中显示价格
(22.34),另一个价格在另一个文本框中...我还有一个
空白
文本框...现在我想将两个价格加在一起并得到一个总数在
的文本框中..
我从网站sumwh得到了这个例子ere ..但它没有显示
十进制数,它只显示整数

请帮助

var number1 = parseInt(document.forms [0 ] .CasesSellingPrice.value);
var number2 = parseInt(document.forms [0] .AccessoriesSellingPrice.value);
document.forms [0] .total.value = number1 + number2;
Right, ok, well I have designed a form that will display a price
(22.34) in
a text box, and another price in the other text box... I also have a
blank
text box... Now I want to add both the prices together and get a total in
the bloank textbox..
I got this example off a website sumwhere.. But it does not display the
decimal number, it only displays the whole number

PLEASE HELP

var number1 = parseInt(document.forms[0].CasesSellingPrice.value);
var number2 = parseInt(document.forms[0].AccessoriesSellingPrice.value);
document.forms[0].total.value = number1 + number2;


此链接可能有所帮助:
http:/ /www.aptools.com/javascript/




我发现它实际上很有趣。如果没有完整的脚本(它的内容很长),请仔细阅读前5或6行重要内容:

< script language =" javascript">


应该是type =" text / javascript",但由于它似乎是在2001年修改的最后一个

,因此它无关紧要。


<! - 从没有javascript的浏览器中隐藏。


也不需要HTML评论实体。我想如果你浏览一个10年的b
岁的浏览器,可能需要它。


函数FormatNumber(数字,小数,分隔符)

{


不确定我是否想要一个名为Number的变量(参数)。

NumToFormat似乎更好,更直观。


// ***************************************** ********* ********

//由经济实惠的生产工具置于公共领域

// 1998年3月21日

//网站: http://www.aptools.com/

//

// 1998年11月24日 - 允许空值的错误

//保持空值固定。现在强制值为0.

//

// 2001年10月28日 - 修改后为分数提供前导0

//小于1.

//

//这个函数接受一个数字来格式化和编号

//指定小数位数到格式化为。可以

//如果指定,可选择使用'。'以外的分隔符。

//

//如果没有指定小数,函数默认为

//小数点后两位。如果没有传递数字,函数

//默认为0.小数分隔符默认为''。''。

//

//如果传递的数字太大而无法格式化为小数

//数字(例如:1.23e + 25),或者转换过程

//结果在这样的数字,原始号码返回

//不变。

// ****************** ******************************** ********

数字+ ="" //强制参数为字符串。

小数+ ="" //强制参数为字符串。

分隔符+ ="" //对字符串强制参数。


Decimals = Decimals.toString()也许?不过可能是马车,我不记得了。
http://www.jibbering.com/faq/#FAQ4_6


似乎要短得多(尽管它缺少一些上面的

功能)并且更容易理解。


这些都没有回答/解决OP的原始问题。在这个主题中看到我的

之前的回复。


-

兰迪

Chance Favors The准备好的心灵

comp.lang.javascript常见问题 - http:// jibbering。 com / faq /



I found it funny actually. Without going through the entire script (its
inherently long), lets go through the first 5 or 6 significant lines:
<script language="javascript">

Should be type="text/javascript", but since it appears to have been last
modified in 2001, its not relevant.

<!-- Hide from browsers without javascript.

Nor is the HTML comment entity needed. I guess if you browse with a 10
year old browser it might be needed.

function FormatNumber(Number,Decimals,Separator)
{

Not sure that I would want a variable (parameter) named Number.
NumToFormat seems better and more intuitive.

// ************************************************** ********
// Placed in the public domain by Affordable Production Tools
// March 21, 1998
// Web site: http://www.aptools.com/
//
// November 24, 1998 -- Error which allowed a null value
// to remain null fixed. Now forces value to 0.
//
// October 28, 2001 -- Modified to provide leading 0 for fractional number
// less than 1.
//
// This function accepts a number to format and number
// specifying the number of decimal places to format to. May
// optionally use a separator other than ''.'' if specified.
//
// If no decimals are specified, the function defaults to
// two decimal places. If no number is passed, the function
// defaults to 0. Decimal separator defaults to ''.'' .
//
// If the number passed is too large to format as a decimal
// number (e.g.: 1.23e+25), or if the conversion process
// results in such a number, the original number is returned
// unchanged.
// ************************************************** ********
Number += "" // Force argument to string.
Decimals += "" // Force argument to string.
Separator += "" // Force argument to string.

Decimals = Decimals.toString() perhaps? Might be buggy though, I don''t
remember.
http://www.jibbering.com/faq/#FAQ4_6

Seems to be a heck of a lot shorter (although it lacks some of the
functionality in the above) and a lot easier to follow.

None of which answers/addresses the OP''s original problem. See my
previous reply in this thread.

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/


这篇关于添加2个文本框的内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆