Calculating Sales Tax for a US State in Javascript
<p>So I'm trying to calculate sales tax for a project and I can't get it to work. Needless to say, I'm still learning javascript.  Here's how it works: If the buyer selects New Jersey, I want to apply a 7% sales tax to the order.  Everywhere else goes to zero.  </p>

<p>Here's a link to the jsFiddle project: <a href="https://jsfiddle.net/JohnOHFS/hpdnmjfL/" rel="nofollow">https://jsfiddle.net/JohnOHFS/hpdnmjfL/</a></p>

<p>Here's my basic form HTML (skipping the opening and closing tags, etc.)</p>

<pre><code>&lt;div id="public"&gt;
                      &lt;div class="row"&gt;
                          &lt;div class="col-xs-7 col-md-7"&gt;
                              &lt;div class="form-group"&gt;
                                  &lt;label for="city"&gt;CITY&lt;/label&gt;
                                  &lt;input type="text" size="20" autocomplete="off" class="city input-small form-control" placeholder="CITY"/&gt;
                              &lt;/div&gt;
                          &lt;/div&gt;
                          &lt;div class="col-xs-4 col-md-4"&gt;
                              &lt;div class="form-group"&gt;
                                  &lt;label for="state"&gt;STATE&lt;/label&gt;
                                  &lt;select class="form-control" id="state" onChange="taxRate()"&gt;
                                      &lt;option value=""&gt;N/A&lt;/option&gt;
                                      &lt;option value="AK"&gt;Alaska&lt;/option&gt;
                                      &lt;option value="AL"&gt;Alabama&lt;/option&gt;
                                      &lt;option value="NH"&gt;New Hampshire&lt;/option&gt;
                                      &lt;option value="NJ"&gt;New Jersey&lt;/option&gt;
                                      &lt;option value="NM"&gt;New Mexico&lt;/option&gt;  
                                    &lt;/select&gt;
                              &lt;/div&gt;
                          &lt;/div&gt;
                      &lt;/div&gt;
                      &lt;div class="row"&gt;
                          &lt;div class="col-xs-5 col-md-5"&gt;
                              &lt;div class="form-group"&gt;
                                  &lt;label for="zipCode"&gt;ZIP CODE&lt;/label&gt;
                                  &lt;input id="zip" type="text" size="6" autocomplete="off" class="zipcode form-control" placeholder="ZIP CODE"/&gt;
                              &lt;/div&gt;
                          &lt;/div&gt;
                      &lt;/div&gt;
                  &lt;/div&gt; &lt;!-- Closes Public --&gt;
                    &lt;div class="row"&gt;
                        &lt;div class="col-xs-7 col-md-7"&gt;
                                &lt;label&gt;ORDER INFORMATION&lt;/label&gt;                                                        
                        &lt;/div&gt;
                    &lt;/div&gt;

                    &lt;div class="row"&gt;
                        &lt;div class="col-xs-7 col-md-7 col-md-offset-1"&gt;
                                &lt;label&gt;SUBTOTAL: &lt;b&gt;$&lt;span id="order_subtotal"&gt;100&lt;/span&gt;&lt;/b&gt;&lt;/label&gt;                                                           
                        &lt;/div&gt;
                    &lt;/div&gt;
                    &lt;div class="row"&gt;
                        &lt;div class="col-xs-7 col-md-7 col-md-offset-1"&gt;
                                &lt;label&gt;TAXES: &lt;b&gt;&lt;span id="order_tax" type="text" value=""&gt;&lt;/span&gt;&lt;/b&gt;&lt;/label&gt;                                                                  
                        &lt;/div&gt;
                    &lt;/div&gt;
                    &lt;div class="row"&gt;
                        &lt;div class="col-xs-7 col-md-7 col-md-offset-1"&gt;
                                &lt;label&gt;ORDER TOTAL: &lt;b&gt;&lt;span id="order_total" type="text" value=""&gt;&lt;/span&gt;&lt;/b&gt;&lt;/label&gt;                                                                  
                        &lt;/div&gt;
                    &lt;/div&gt;
</code></pre>

<p>Here's the Javascript:</p>

<pre><code>function taxRate() {
    var tax_rate = .07;
    var order_taxes = 0;
    var subtotal = document.getElementById("order_subtotal").value;
    subtotal = parseInt(subtotal);
    var total = 0;
    var state = document.getElementById("state").value;
    var selection = state.options[state.selectedIndex].value;
    if (selection == 'New Jersey') {
      order_taxes += tax_rate * subtotal;
    } 
    if (selection == 'else') {
    order_taxes = 0;
    }
    if (selection == 'New Jersey') {
    tax_percent = tax_rate * 100;
    } 
    if (selection == 'else') {
    tax_percent = 0;
    }

    var el = document.getElementById('order_tax');
    el.textContent = order_taxes;

    var total = subtotal + order_taxes;
    var el1 = document.getElementById('order_total');
    el1.textContent = total;

}
</code></pre>

<p>Here are my questions.<br>
 1.  What am i doing wrong?
 2.  How do I pass tax_percent from this javascript into the html for submittal to Stripe?</p>

<p>Thanks!</p>