需要帮助编写Javascript来添加值

时间:2016-04-21 21:08:40

标签: javascript jquery

我需要帮助为我的表单编写JavaScript代码。我需要在文本字段中添加值(信用卡,发薪日贷款和无担保个人贷款),如果总金额超过或等于10000美元,提交时应将用户带到第1页,否则第2页。我只是想要添加前三个字段,用户在其他字段中输入的内容无关紧要。这是我的表格:

<form action="/fsg?pageId=0bd004f9-aabc-486e-be09-bf2621555e3e&amp;variant=b" method="POST">
<input type="hidden" name="pageId" value="0bd004f9-aabc-486e-be09-bf2621555e3e"><input type="hidden" name="pageVariant" value="b">
<fieldset class="clearfix" style="width: 297px; height: -17px;">
<div class="lp-pom-form-field clearfix" id="container_What_state_do_you_live_in">
<label for="What_state_do_you_live_in" class="main lp-form-label" id="label_What_state_do_you_live_in">
   State? *</label><select id="What_state_do_you_live_in" name="What_state_do_you_live_in" class="text form_elem_What_state_do_you_live_in">
   <option value="">Select a State</option>
   <option value="Arizona">Arizona</option>
   <option value="California">California</option>
   <option value="Florida">Florida</option>
   <option value="Michigan">Michigan</option>
   <option value="Nevada">Nevada</option>
   <option value="New York">New York</option>
   <option value="Pennsylvania">Pennsylvania</option>
   <option value="Texas">Texas</option>
   <option value="Virginia">Virginia</option>
   <option value="I reside in another state.">I reside in another state.</option></select>
</div>
<div class="lp-pom-form-field clearfix" id="container_credit_cards">
<label for="credit_cards" class="main lp-form-label" id="label_credit_cards">Credit Cards</label><input type="text" id="credit_cards" name="credit_cards" class="text form_elem_credit_cards">
</div>
<div class="lp-pom-form-field clearfix" id="container_payday_loans">
<label for="payday_loans" class="main lp-form-label" id="label_payday_loans">Payday Loans</label><input type="text" id="payday_loans" name="payday_loans" class="text form_elem_payday_loans">
</div>
<div class="lp-pom-form-field clearfix" id="container_unsecured_personal_loans">
<label for="unsecured_personal_loans" class="main lp-form-label" id="label_unsecured_personal_loans">Unsecured Personal Loans</label><input type="text" id="unsecured_personal_loans" name="unsecured_personal_loans" class="text form_elem_unsecured_personal_loans">
</div>
<div class="lp-pom-form-field clearfix" id="container_student_loans">
<label for="student_loans" class="main lp-form-label" id="label_student_loans">Student Loans</label><input type="text" id="student_loans" name="student_loans" class="text form_elem_student_loans">
</div>
<div class="lp-pom-form-field clearfix" id="container_auto_loan">
<label for="auto_loan" class="main lp-form-label" id="label_auto_loan">Auto Loan</label><input type="text" id="auto_loan" name="auto_loan" class="text form_elem_auto_loan">
</div>
<div class="lp-pom-form-field clearfix" id="container_medical_bills">
<label for="medical_bills" class="main lp-form-label" id="label_medical_bills">Medical Bills</label><input type="text" id="medical_bills" name="medical_bills" class="text form_elem_medical_bills">
</div>
<input type="submit" name="submit" id="submit" value="Submit">
</form>

1 个答案:

答案 0 :(得分:1)

var total = $('#Creditcards').val() + $('#Payday').val() + $('#Unsecured').val();
    $('.submit').click(function(){
    if(total<10000) 
      {window.href.location = "x"}
    else{
       window.href.location = "y";
    }
})