Note that there are some explanatory texts on larger screens.

plurals
  1. PONeed help editing a bit of jquery code that changes price options
    primarykey
    data
    text
    <p>I am new to jQuery so forgive me if this seems a like odd. At the moment I have the code below. The price when you <code>select 1</code> is <code>12.99</code>, when you <code>select 2</code> the price is <code>11.99</code>and any selection from <code>3 or over is 10.99</code>. The numbers get multiplied by the quantity selected. What I need help with is changing when the <code>base price changes</code>. I want the price from <code>1 to 4</code> to be <code>12.99</code>. Then from <code>5 to 9</code> to be <code>11.99</code> then anything from <code>10</code> to be <code>10.99</code>. I hope this makes sense. </p> <pre><code>&lt;script type="text/javascript"&gt; jQuery(document).ready( function(){ var map = [ '12.99', '11.99', '10.99' ]; jQuery('#payslips-required').change(function(){ var o = parseInt($(this).val()) &lt; 3 ? jQuery(this).val()-1 : 2; jQuery('#price').val(map[o]).addClass('hidden'); var price = $('#price').val(); var quantity = $('#payslips-required').val(); var total = price * quantity; jQuery('#total').val(total).addClass('hidden'); }); }); &lt;/script&gt; &lt;select id="payslips-required"&gt; &lt;option value="1"&gt;1&lt;/option&gt; &lt;option value="2"&gt;2&lt;/option&gt; &lt;option value="3"&gt;3&lt;/option&gt; &lt;option value="4"&gt;4&lt;/option&gt; &lt;option value="5"&gt;5&lt;/option&gt; &lt;option value="6"&gt;6&lt;/option&gt; &lt;option value="7"&gt;7&lt;/option&gt; &lt;option value="8"&gt;8&lt;/option&gt; &lt;option value="9"&gt;9&lt;/option&gt; &lt;option value="10"&gt;10&lt;/option&gt; &lt;option value="11"&gt;11&lt;/option&gt; &lt;option value="12"&gt;12&lt;/option&gt; &lt;/select&gt; &lt;input type='text' id="price" /&gt; Each &lt;br /&gt; &lt;input type='text' id="total" /&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload