javascript - Appending a % on the end of a calculated value in jQuery? -


i have form calculates few values , spits out grade. have grade precent. come out integers, ie: 100.00.

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 account</h2>         <h3 class="fs-subtitle">this 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 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 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 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 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 -->             <!-- field 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 this?</div>     </fieldset> 

i have tried few ways of += '%' + '%' can't seem right.

changing target input element from:

type="number"  

to:

type="text" 

should fix issue. use:

jquery("#edit-submitted-acquisition-percent-change").val( acqtotal + '%' ); 

Comments