onSubmit无法在任何浏览器中运行

时间:2013-04-09 17:55:28

标签: javascript html

我有一个简单的表格。我想用我的简单公式计算隐藏的表单字段的值(从下拉除以100然后将其与文本字段中的估计工资相乘。

但是由于某些奇怪的原因,onSubmit不能在表单上工作。我想在提交表单时计算上面的值,但是没有在任何浏览器上调用它。这真是个奇怪的问题。

以下是代码:

  <script type="text/javascript">
function calc1()
{
var a= document.getElementById('inf_custom_FLRaterClassCode0').value;
  var b = document.getElementById('inf_custom_FLRaterEstimatedPayroll').value; 
document.getElementById('inf_custom_EstimatedQuote').value=parseFloat(a)/100 * parseFloat(b) ; 


}

</script>

<form accept-charset="UTF-8" action="https://kg933.infusionsoft.com/app/form/process/968a6b704587136af8684f30cc8c5cf4" class="infusion-form" method="GET" onSubmit="calc1();">
    <input name="inf_form_xid" type="hidden" value="968a6b704587136af8684f30cc8c5cf4" />
    <input name="inf_form_name" type="hidden" value="Full Quote - Florida Rate" />
    <input name="infusionsoft_version" type="hidden" value="1.28.7.21" />
    <div class="infusion-field">
        <label for="inf_field_FirstName">First Name *</label>
        <input class="infusion-field-input-container" id="inf_field_FirstName" name="inf_field_FirstName" type="text" />
    </div>
    <div class="infusion-field">
        <label for="inf_field_LastName">Last Name *</label>
        <input class="infusion-field-input-container" id="inf_field_LastName" name="inf_field_LastName" type="text" />
    </div>
    <div class="infusion-field">
        <label for="inf_field_Company">Company *</label>
        <input class="infusion-field-input-container" id="inf_field_Company" name="inf_field_Company" type="text" />
    </div>
    <div class="infusion-field">
        <label for="inf_field_Email">Email *</label>
        <input class="infusion-field-input-container" id="inf_field_Email" name="inf_field_Email" type="text" />
    </div>
    <div class="infusion-field">
        <label for="inf_field_Phone1">Phone 1 *</label>
        <input class="infusion-field-input-container" id="inf_field_Phone1" name="inf_field_Phone1" type="text" />
    </div>
    <div class="infusion-field">
        <label for="inf_custom_FLRaterClassCode0">FL Rater - Class Code #2 *</label>
        <select id="inf_custom_FLRaterClassCode0" name="inf_custom_FLRaterClassCode0"><option value="">Please select one</option><option value="9519">9519</option><option value="5473">5473</option><option value="5472">5472</option><option value="9516">9516</option><option value="8393">8393</option><option value="8380">8380</option><option value="5188">5188</option></select>
    </div>
    <div class="infusion-field">
        <label for="inf_custom_FLRaterEstimatedPayroll">FL Rater - Estimated Payroll *</label>
        <input class="infusion-field-input-container" id="inf_custom_FLRaterEstimatedPayroll" name="inf_custom_FLRaterEstimatedPayroll" type="text" />
    </div>
    <input name="inf_custom_EstimatedQuote" type="hidden" value="" />
    <div class="infusion-submit">
        <input type="submit" value="Submit" />
    </div>
</form>

3 个答案:

答案 0 :(得分:2)

问题在于您尝试按ID访问元素,但应按名称进行访问。

替换

document.getElementById('inf_custom_EstimatedQuote').value=parseFloat(a)/100 * parseFloat(b) ; 

document.getElementsByName('inf_custom_EstimatedQuote')[0].value=parseFloat(a)/100 * parseFloat(b) ; 

或在发送表单之前为您要更改的输入提供ID。

答案 1 :(得分:1)

它的“onsubmit”不是“onSubmit”

event_form_onsubmit

答案 2 :(得分:0)

calc1()在提交表单之前运行。但是,当您提交表单时,您会重新加载页面(“https://kg933.infusionsoft.com/app/form/process/968a6b704587136af8684f30cc8c5cf4”),因此您无法查看计算结果,因为新网页已打开。