Note that there are some explanatory texts on larger screens.

plurals
  1. POGet amount and put elsewhere
    primarykey
    data
    text
    <p>I´d like to get the amount between "(+$" and ")" and add it to the value of the inputbox.</p> <p>For example, you select the following:<br /> Solero Exotic (+$1.85)<br /> Cappuccino (+$2.49)<br /> iMac 27-inch 3.1GHz (+$1,999.00)<br /></p> <p>These amounts will be subtracted from the options you've selected:<br /> 1.85<br /> 2.49<br /> 1,999.00</p> <p>The inputbox will display: <b>2003.34</b></p> <p><br /></p> <p>Anyone know a javascript code that can do this? (without adding more attributes to the Option tag)</p> <p><br /></p> <pre><code>&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"&gt; &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt; &lt;head&gt; &lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8" /&gt; &lt;title&gt;Get amount and put elsewhere&lt;/title&gt; &lt;/head&gt; &lt;body&gt; &lt;form action=""&gt; &lt;fieldset&gt; &lt;ul style="list-style:none;padding-left:0;"&gt; &lt;li&gt;Ice Cream: &lt;select class="optionsIceCream" name="IceCream"&gt; &lt;option value="IceCream01"&gt;Select Ice Cream&lt;/option&gt; &lt;option value="IceCream02"&gt;Solero Exotic (+$1.85)&lt;/option&gt; &lt;option value="IceCream03"&gt;Magnum Ecuador (+$4.85)&lt;/option&gt; &lt;option value="IceCream04"&gt;Cornetto Enigma (+$2.00)&lt;/option&gt; &lt;/select&gt; &lt;/li&gt; &lt;li&gt;Coffee: &lt;select class="optionsCoffee" name="Coffee"&gt; &lt;option value="Coffee01"&gt;Select Coffee&lt;/option&gt; &lt;option value="Coffee02"&gt;Cup of Joe (+$0.99)&lt;/option&gt; &lt;option value="Coffee03"&gt;Cappuccino (+$2.49)&lt;/option&gt; &lt;option value="Coffee04"&gt;Latte Macchiato (+$2.99)&lt;/option&gt; &lt;/select&gt; &lt;/li&gt; &lt;li&gt;Computers: &lt;select class="optionsComputers" name="Computers"&gt; &lt;option value="Computer01"&gt;Select Computer&lt;/option&gt; &lt;option value="Computer02"&gt;Dell Inspiron 620 (+$449.99)&lt;/option&gt; &lt;option value="Computer03"&gt;HP Pavilion dv7t (+$949.99)&lt;/option&gt; &lt;option value="Computer04"&gt;iMac 27-inch 3.1GHz (+$1,999.00)&lt;/option&gt; &lt;/select&gt; &lt;/li&gt; &lt;/ul&gt; Total: &lt;input class="totalAmount" type="text" disabled="disabled" value="0.00" /&gt; &lt;/fieldset&gt; &lt;/form&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p><br /> <br /> <br /> <br /> <strong><em>*</em>**<em>*</em>**<em>*</em>**<em>*</em>**<em>*</em>**<em>*</em>**<em></strong> UPDATE: 09-09-2011 <strong></em>**<em>*</em>**<em>*</em>**<em>*</em>**<em>*</em>**<em>*</em>**<em>*</em></strong></p> <p><br /> I found a solution, thanks to <a href="http://answers.yahoo.com/activity?show=TxHLcJ57aa" rel="nofollow">Dominic H</a> from <i>Yahoo! Answers</i> <br /><br /> It's simple but very effective and it works perfectly! <br /><br /> Here's the entire code: <br /><br /></p> <pre><code>&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"&gt; &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt; &lt;head&gt; &lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8" /&gt; &lt;title&gt;Get amount and put elsewhere&lt;/title&gt; &lt;/head&gt; &lt;body&gt; &lt;form action=""&gt; &lt;fieldset&gt; &lt;ul style="list-style:none;padding-left:0;"&gt; &lt;li&gt;Ice Cream: &lt;select class="optionsIceCream" name="IceCream"&gt; &lt;option value="IceCream01"&gt;Select Ice Cream&lt;/option&gt; &lt;option value="IceCream02"&gt;Solero Exotic (+$1.85)&lt;/option&gt; &lt;option value="IceCream03"&gt;Magnum Ecuador (+$4.85)&lt;/option&gt; &lt;option value="IceCream04"&gt;Cornetto Enigma (+$2.00)&lt;/option&gt; &lt;/select&gt; &lt;/li&gt; &lt;li&gt;Coffee: &lt;select class="optionsCoffee" name="Coffee"&gt; &lt;option value="Coffee01"&gt;Select Coffee&lt;/option&gt; &lt;option value="Coffee02"&gt;Cup of Joe (+$0.99)&lt;/option&gt; &lt;option value="Coffee03"&gt;Cappuccino (+$2.49)&lt;/option&gt; &lt;option value="Coffee04"&gt;Latte Macchiato (+$2.99)&lt;/option&gt; &lt;/select&gt; &lt;/li&gt; &lt;li&gt;Computers: &lt;select class="optionsComputers" name="Computers"&gt; &lt;option value="Computer01"&gt;Select Computer&lt;/option&gt; &lt;option value="Computer02"&gt;Dell Inspiron 620 (+$449.99)&lt;/option&gt; &lt;option value="Computer03"&gt;HP Pavilion dv7t (+$949.99)&lt;/option&gt; &lt;option value="Computer04"&gt;iMac 27-inch 3.1GHz (+$1,999.00)&lt;/option&gt; &lt;/select&gt; &lt;/li&gt; &lt;/ul&gt; Total: &lt;input class="totalAmount" type="text" disabled="disabled" value="0.00" /&gt; &lt;/fieldset&gt; &lt;/form&gt; &lt;script type="text/javascript"&gt; //&lt;![CDATA[ (function () { var selects = document.getElementsByTagName("select"), L = selects.length, i; for (i = 0; i &lt; L; i++) { selects[i].setAttribute("onchange", "calcTotal();"); } }()); function calcTotal() { var icecream = [0.00, 1.85, 4.85, 2.00], coffee = [0.00, 0.99, 2.49, 2.99], computer = [0.00, 449.99, 949.99, 1999.00], total = document.getElementsByTagName("input")[0], select = document.getElementsByTagName("select"); total.value = (icecream[select[0].selectedIndex] + coffee[select[1].selectedIndex] + computer[select[2].selectedIndex]).toFixed(2); } //]]&gt; &lt;/script&gt; &lt;/body&gt; &lt;/html&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.
    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