在文本框,复选框和下拉菜单中添加值 [英] Adding values in textbox, checkbox and dropdown menu

查看:59
本文介绍了在文本框,复选框和下拉菜单中添加值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个程序,它会在文本框,复选框和下拉菜单中添加值。它的运行方式是,文本框将被添加,然后如果客户选中复选框,它将被添加到付款中,如果没有选中,则无需额外付款。然后是下拉菜单,无论客户选择什么,它都会被添加到付款中。

如何编写我的代码以获得所有值的总和?



这些是我的代码到目前为止。



  function  subtotal(){
var a = document .getElementById( sff)。value;
var b = document .getElementById( osf)。value

var stotal = a + b;
document .getElementById( st).innerHTML = $ + stotal;

} < / pre >





 <   pre     lang   =  HTML >  <  输入    type   =  text    id   =  osf < span class =code-attribute>  占位符  =  $ 0.00 <跨度class =code-attribute>   style   =  float:left;    onchange   =  subtotal()  /   >  
< input type = text id = sff 占位符 = $ 0.00 style = float:left; onchange = 小计( ) / >
< 选择 style = margin:3px 0 0 55px;宽度:48%;位置:绝对;向左飘浮; >
& lt; option value =>(选择要购买的代理服务年数)& lt ; / option>
& lt; option value =a1> 1年@ $ 99.00 /年(服务至2015年12月)& lt; / option>
& lt; option value = a2> SAVE!2年(@ $ 89.10 /年)仅售178.20美元(2016年12月服务) - 节省19.80美元< /选项>
& lt; option value =a3>节省!3年(@ $ 80.52 /年)仅售$ 241.56(服务至2017年12月) - 节省$ 55.44& lt; / option>
& lt; option value =a4> SAVE!4年( @ $ 73.06 /年)仅售292.24美元(2018年12月服务) - 节省$ 103.75& lt; / option>
& lt; option value =a4> SAVE!5年(@ $ 66.56 /年)仅售$ 332.80(服务至2019年12月) - 节省$ 162.20& lt; / option>
& lt; / select>
< 输入 type = 复选框 id = cbx2 / > ($ 35.00) - 准备IRS表格SS-4(联邦EIN号码)< / pre >

解决方案

+ stotal;

} < / pre >





 <   pre     lang   =  HTML >  <  输入    type   =  text    id   =  osf < span class =code-attribute>  占位符  =  

0.00 style = float:left; onchange = subtotal() / >
< input type = text id = sff 占位符 =


0.00 style = float:left; onchange = subtotal() / >
< 选择 style = margin:3px 0 0 55px;宽度:48%;位置:绝对;向左飘浮; >
& lt; option value =>(选择要购买的代理服务年数)& lt ; / option>
& lt; option value =a1> 1年@


I have this program that will add the value in a textbox, checkbox and dropdown menu. The way it run is, the textboxes will be added, then if the customer checks the checkbox, it will be added to the payment if not checked, no additional payment. then the drop down menu, whatever the customer will choose, it will be added to the payment.
How will I write my code to get the total of all the values?

These are my codes so far.

function subtotal(){
    var a = document.getElementById("sff").value;
    var b = document.getElementById("osf").value

    var stotal = a+b;
    document.getElementById("st").innerHTML = "$" + stotal;

}</pre>



<pre lang="HTML"><input type="text" id="osf" placeholder="$0.00" style="float:left;" onchange="subtotal()"/>
<input type="text" id="sff" placeholder="$0.00" style="float:left;" onchange="subtotal()"/>
<select style="margin: 3px 0 0 55px; width:48%; position: absolute; float: left; ">
                    &lt;option value="">(Select Number Of Years Of Agent Service To Purchase)&lt;/option>
                    &lt;option value="a1">1 Year @ $99.00/yr (Service to December 2015)&lt;/option>
                    &lt;option value="a2">SAVE! 2 Years (@ $89.10/yr) for only $178.20 (Service to December 2016) - Save $19.80&lt;/option>
                    &lt;option value="a3">SAVE! 3 Years (@ $80.52/yr) for only $241.56 (Service to December 2017) - Save $55.44&lt;/option>
                    &lt;option value="a4">SAVE! 4 Years (@ $73.06/yr) for only $292.24 (Service to December 2018) - Save $103.75&lt;/option>
                    &lt;option value="a4">SAVE! 5 Years (@ $66.56/yr) for only $332.80 (Service to December 2019) - Save $162.20&lt;/option>
                &lt;/select>
<input type="checkbox" id="cbx2"/>($35.00) - Prepare IRS Form SS-4 (Federal EIN Number)</pre>

解决方案

" + stotal; }</pre>



<pre lang="HTML"><input type="text" id="osf" placeholder="


0.00" style="float:left;" onchange="subtotal()"/> <input type="text" id="sff" placeholder="


0.00" style="float:left;" onchange="subtotal()"/> <select style="margin: 3px 0 0 55px; width:48%; position: absolute; float: left; "> &lt;option value="">(Select Number Of Years Of Agent Service To Purchase)&lt;/option> &lt;option value="a1">1 Year @


这篇关于在文本框,复选框和下拉菜单中添加值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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