简体   繁体   English

价格计算器Javascript帮助-共享变量的值

[英]Price Calculator Javascript help - sharing a variable's value

I am using CodeCanyon's Price Calculator, and am having some Javascript trouble. 我正在使用CodeCanyon的价格计算器,并且遇到了一些Javascript问题。

The first field calculates the tuition amount based on the number of credit hours. 第一个字段根据学时数计算学费。

The second field (where I'm having trouble) is supposed to take the number of credit hours selected from the first field, divide it by 3 to get the number of classes, and then multiply by 100 to arrive at the amount of money needed for textbooks. 第二个字段(我遇到麻烦的地方)应该采用从第一个字段中选择的学时数,将其除以3得到班级数量,然后乘以100得出所需的金额用于教科书。

I have tried achieving this equation with Javascript and some ASP, but haven't been successful. 我曾尝试使用Javascript和一些ASP来实现此等式,但并未成功。 I'm no Javascript expert, but here is the code as it presently stands. 我不是Javascript专家,但是这里是目前的代码。 Any help is much appreciated! 任何帮助深表感谢!

HTML markup HTML标记

The "f_4" and "f_7-textbooks" are variables named in the script below. “ f_4”和“ f_7-教科书”是在以下脚本中命名的变量。 f_4 is the number of credit hours selected. f_4是所选的学时数。 In f_7-textbook, I've attempted to call the value of f_4, divide it by 3 and multiply it by the value sent from the database (hence, <%=budgetRS("budget_BooksandSupplies_sem1")%>), which is set to "100". 在f_7教科书中,我尝试调用f_4的值,将其除以3,然后乘以从数据库发送的值(因此,<%= budgetRS(“ budget_BooksandSupplies_sem1”)%>),该值设置为“ 100”。

<fieldset>
<p>1 class = 3 credit hours.</p>
<p>
    <label>Number of Credit Hours: <input class="spinner" type="text" id="f_4" name="f_4" data-spinner='{"min": 0, "max": 42, "step": 3}' data-default="0" value="3" data-cost="<%=FormatNumber(budgetRS("budget_Tuition_sem1"), 2)%>"/></label> 
    <span class="staticPrice">
    </span>
</p>
<p>
    Textbook Estimate ($<%=budgetRS("budget_BooksandSupplies_sem1")%>/3 credit hours): 
    <input type="hidden" name="f_7-textbooks" value="{f_4}/3*<%=budgetRS("budget_BooksandSupplies_sem1")%>" />
</p>
</fieldset>

Javascript Java脚本

<script type="text/javascript">
$(function(){
    var form = $('#jquery-order-form');

    //form.find('span.staticPrice').remove();
    form.find('option').each(function(i){
        var opt = $(this)
        opt.text(opt.val());
    });

    var items = [];
    items['f_4'] = 'Credit Hours ($<%=budgetRS("budget_Tuition_sem1")%>/credit hour)';
    items['f_7-textbooks'] = 'Textbook Estimate ($<%=budgetRS("budget_BooksAndSupplies_sem1")%>/credit hour)';

    });

});
</script>

The full code for this calculator is available at http://media.briercrest.ca/calculators/collegecalculator.asp 有关此计算器的完整代码,请访问http://media.briercrest.ca/calculators/collegecalculator.asp。

You are trying to use client side values in your serverside code which has no access to this data and is resulting in being output. 您正在尝试在服务器端代码中使用客户端值,该值无法访问此数据并导致输出。

<input type="hidden" name="f_7-textbooks" value="{f_4}/3*100">

You should use only client side values in your client side code and vice versa for your server side. 您应该在客户端代码中仅使用客户端值,反之亦然。

The code below should get the value you require. 下面的代码应获取您所需的值。

$('.ui-spinner-button').click(function() { $(this).siblings('input').change(); });

$('#f_4').spinner().change(function() {
   var f4Val = $('#f_4').val();
   var calcValue = (f4Val/3)*100;
   $('input[name="f_7-textbooks"]').val(calcValue);
});

See this fiddle 看到这个小提琴

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM