2015-07-17 2 views
0

У меня есть форма, которая вычисляет несколько значений и выплескивает оценку. Я бы хотел, чтобы класс был предсезонным. Они уже выходят как целые числа, т. Е. 100,00.Добавление% в конце расчетного значения в jQuery?

var acqAmount1 = Number(jQuery("#edit-submitted-acquisition-amount-1").val().replace(/,/g,"")); 
    var acqAmount2 = Number(jQuery("#edit-submitted-acquisition-amount-2").val().replace(/,/g,"")); 
    var acqTotal = 0; 

    if (acqAmount1) { 
     acqAmount1 = parseFloat(acqAmount1); 
    } else { 
     acqAmount1 = 0; 
    } 

    if (acqAmount2) { 
     acqAmount2 = parseFloat(acqAmount2); 
    } else { 
     acqAmount2 = 0; 
    } 

    if (acqAmount1 > 0 && acqAmount2 > 0) { 
     acqTotal = ((acqAmount2 - acqAmount1)/acqAmount1 * 100).toFixed(2); 
    } else { 
     acqTotal = 0; 
    } 

    jQuery("#edit-submitted-acquisition-percent-change").val(acqTotal); 

    grade += getAcquisitionPoints(acqTotal); 




<fieldset> 
     <h2 class="fs-title">Create your account</h2> 
     <h3 class="fs-subtitle">This is step 2</h3> 
      <!-- Begin Total Number of Donors in Year 1 Field --> 
       <div class="form-item webform-component webform-component-textfield hs_total_number_of_donors_in_year_1 field hs-form-field" id="webform-component-acquisition--amount-1"> 

        <label for="edit-submitted-acquisition-amount-1 total_number_of_donors_in_year_1-99a6d115-5e68-4355-a7d0-529207feb0b3_6344">What was your number of total donors in year 1?</label><span class="required"> * </span> 

        <input id="edit-submitted-acquisition-amount-1" class="form-text hs-input" name="submitted total_number_of_donors_in_year_1" required="required" size="60" maxlength="128" type="number" value="" placeholder="" data-rule-required="true" data-msg-required="Please enter a valid number"> 
        <span class="error1" style="display: none;"> 
         <i class="error-log fa fa-exclamation-triangle"></i> 
        </span> 
       </div> 
      <!-- End Total Number of Donors in Year 1 Field --> 

      <!-- Begin Total Number of Donors in Year 2 Field --> 
       <div class="form-item webform-component webform-component-textfield hs_total_number_of_donors_in_year_2 field hs-form-field" id="webform-component-acquisition--amount-2"> 

        <label for="edit-submitted-acquisition-amount-2 total_number_of_donors_in_year_2-99a6d115-5e68-4355-a7d0-529207feb0b3_6344">What was your number of total donors in year 2?</label><span class="required"> * </span> 

        <input id="edit-submitted-acquisition-amount-2" class="form-text hs-input" name="submitted[acquisition][amount_2] total_number_of_donors_in_year_2" required="required" size="60" maxlength="128" type="number" value="" placeholder="" data-rule-required="true" data-msg-required="Please enter a valid number"> 
        <span class="error1" style="display: none;"> 
         <i class="error-log fa fa-exclamation-triangle"></i> 
        </span> 
       </div> 
       <!-- End Total Number of Donors in Year 2 Field --> 

      <!-- Begin Calc of Total Number of Donors Fields --> 
      <!-- THIS FIELD IS NOT EDITABLE | GRAYED OUT --> 
       <div class="form-item webform-component webform-component-textfield webform-container-inline hs_total_donor_percent_change field hs-form-field"> 

        <label for="edit-submitted-acquisition-percent-change total_donor_percent_change-99a6d115-5e68-4355-a7d0-529207feb0b3_6344">Total Donors Percent Change</label><span class="required"> * </span> 

        <input id="edit-submitted-acquisition-percent-change" class="form-text hs-input" name="total_donor_percent_change" readonly="readonly" size="60" maxlength="128" type="number" value="" placeholder="0"><span class="field-suffix">%</span> 
       </div> 
       <!-- End Calc of Total Number of Donors Fields --> 
     <input type="button" data-page="2" name="previous" class="previous action-button" value="Previous" /> 
     <input type="button" data-page="2" name="next" class="next action-button" value="Next" /> 
     <div class="explanation btn btn-small modal-trigger" data-modal-id="modal-3">What Is This?</div> 
    </fieldset> 

Я попробовал несколько способов += '%'+ '%', но не могу показаться, чтобы получить это право.

+1

Не имеет значения 'grade = grade + '%';' work? – D4V1D

+1

'jQuery (" # edit-given-purchase-percent-change "). Val (acqTotal + '%');' не работает? – Phylogenesis

+0

@ D4V1D 'grade + = getAcquisitionPoints (acqTotal); класс = класс + '%'; 'не вызывает никаких ошибок, но также не добавляет '%':/ –

ответ

0

Изменение элемента целевого input от:

type="number" 

To:

type="text" 

Если устранить проблему. Использование:

jQuery("#edit-submitted-acquisition-percent-change").val(acqTotal + '%'); 
+0

Да, это он, решил! Благодаря Schism и PeterKA они оба предоставили ответы на проблему. Цените помощь! –

Смежные вопросы