Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Nov 2010
    Posts
    26
    Thanks
    1
    Thanked 1 Time in 1 Post

    HELP how to show the difference in a form

    is there a simple way or any way at all of making the ($50.00) ($40.00) ($30.00) ($20.00) show the difference instead... like if i chose $40.00 then the $50.00 would say +$10.00 and the 30 and 20 would say -$10.00 and -$20.00
    Code:
    <p align="left">CASE</p>
    					<center>
    					<select name="caseselect" style="width:625px" onchange="Calculate(); swapImage(this,'caseimg');">
    						<option value="50#COOLER MASTER Elite 310red.jpg" selected="1">COOLER MASTER Elite 310 Red ($50.00)</option>
    						<option value="40#COOLER MASTER Elite 310blue.jpg">COOLER MASTER Elite 310 Blue ($40.00)</option>
    						<option value="30#COOLER MASTER Elite 310orange.jpg">COOLER MASTER Elite 310 Orange ($30.00)</option>
    						<option value="20#COOLER MASTER Elite 310silver.jpg">COOLER MASTER Elite 310 Silver ($20.00)</option>
    					</select>

  • #2
    New Coder
    Join Date
    Nov 2010
    Posts
    26
    Thanks
    1
    Thanked 1 Time in 1 Post
    if not... thats fine you guys have helped me enough i guess... but i really do believe im getting close to the end of this all

  • #3
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,189
    Thanks
    75
    Thanked 4,341 Times in 4,307 Posts
    Code:
    <html>
    <head>
    <script>
    function Calculate() { };
    function swapImage() { };
    
    function fixAmounts(sel)
    {
        var curopt = sel.options[sel.selectedIndex]; // chosen option
        var curamt = parseFloat( curopt.value.split("#")[0] ); // price of that option
        for ( var op = 0; op < sel.options.length; ++op )
        {
            var option = sel.options[op];
            var oamt = parseFloat( option.value.split("#")[0] );
            var diff = oamt - curamt;
            var sign = ( diff > 0 ) ? "+" : (diff < 0 ) ? "-" : "";
            if ( diff == 0 ) diff = curamt; // chosen option gets actual price??
            option.text = option.text.substring( 0, option.text.indexOf("(") )
                        + "(" + sign + "$" + Math.abs(diff).toFixed(2) + ")";
        }
    }
    </script>
    </head>
    <body>
    <form>
    <select name="caseselect" style="width:625px" onchange="fixAmounts(this); Calculate(); swapImage(this,'caseimg');">
    	<option value="50#COOLER MASTER Elite 310red.jpg" selected="1">COOLER MASTER Elite 310 Red ($50.00)</option>
    	<option value="40#COOLER MASTER Elite 310blue.jpg">COOLER MASTER Elite 310 Blue (-$10.00)</option>
    	<option value="30#COOLER MASTER Elite 310orange.jpg">COOLER MASTER Elite 310 Orange (-$20.00)</option>
    	<option value="20#COOLER MASTER Elite 310silver.jpg">COOLER MASTER Elite 310 Silver (-$30.00)</option>
    </select>
    </form>
    </body>
    If you opt to omit the line in red, then change the amount in magenta to $0.00, of course.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •