Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

calculation problem with Javascript

Status
Not open for further replies.

swazisteve

Programmer
Feb 9, 2014
8
0
0
NZ
Hi there, I am new to Javascript so hope you can help

Hope you can help. I have a form that on drop down picks a product that uses a formula to generate a calculation.

the first one works, but the others do not and even though I choose the other products from the drop down it still uses the code from the first product in the select box:
code below:

Code:
<script type="text/javascript">

    jQuery(document).ready(function($) {
        //Items
        $("#input_4_11").on('keyup', do_maths);
        //time taken
        $("#input_4_35").on('keyup', do_maths);
        //Hourly Rate
        $("#input_4_14").on('keyup', do_maths);
         
                
        function do_maths()
        {
          

            if($.isNumeric($('#input_4_11').val()) && $.isNumeric($('#input_4_35').val()) && $.isNumeric($('#input_4_14').val())) 
            {
            
                if($(".result-selected").html() !== "Select...")
                {
                    if($(".result-selected").html("Printing drawing"))
                    {
                        //(RTV Xporter, Xporter PRO and Drawing Manager)  = .25
                      costs1 = 0.25;
                      product_cost1 = 49;
                        
                        var qty = $("#input_4_11").val();
                    var hourly = $("#input_4_14").val();
                    var time_taken = $("#input_4_35").val();
                    
                    var time_saved = ((qty * time_taken) - ((qty * time_taken)  * costs1))/60;
                    
              
                    var money_saved = time_saved * hourly;
                    
                    money_saved = money_saved.toFixed(2);
  
                    $('#input_4_20').val(time_saved);
                    
                    
                    //Money Saved---------------------------------------------------------------
                    //(Time Saved / 60) * Hourly Rate
                    $('#input_4_22').val(money_saved);
                    
                    //RTV Product Cost----------------------------------------------------------
                    $('#input_4_24').val(product_cost1 - 5);
                    
                    //Automatic ROI------------------------------------------------------------
                    $('#input_4_23').val(money_saved - product_cost1);
                    
                    }
                    else if($(".result-selected").html("Creating digital files"))
                    {
                        //(RTV Xporter, Xporter PRO and Drawing Manager) = .25
                 costs = 0.25;
                product_cost = 9.99 + 49 + 255;
                        
                        var qty = $("#input_4_11").val();
                    var hourly = $("#input_4_14").val();
                    var time_taken = $("#input_4_35").val();
                    
                    var time_saved = ((qty * time_taken) - ((qty * time_taken)  * costs))/60;
                    
              
                    var money_saved = time_saved * hourly;
                    
                    money_saved = money_saved.toFixed(2);
  
                    $('#input_4_20').val(time_saved);
                    
                    
                    //Money Saved---------------------------------------------------------------
                    //(Time Saved / 60) * Hourly Rate
                    $('#input_4_22').val(money_saved);
                    
                    //RTV Product Cost----------------------------------------------------------
                    $('#input_4_24').val(product_cost);
                    
                    //Automatic ROI------------------------------------------------------------
                    $('#input_4_23').val(money_saved - product_cost);
                    
                    
                    }
                    else if($(".result-selected").html("Combined printing and creating digital files"))
                    {
                        //(RTV Xporter, Xporter PRO and Drawing Manager) = .5
                       // costs = 0.5;
                        //product_cost = 9.99 + 49 + 255;
                        
                    }
                    else if($(".result-selected").html("Update title blocks / drawing sheets"))
                    {
                        //(RTV Drawing Manager) = .1
                         //costs = 0.1;
                        // product_cost = 255;
                    }
                    else if($(".result-selected").html("Adding and updating revisions on title blocks / drawing sheets"))
                    {
                        //(RTV Drawing Manager) = .35
                        //costs = 0.35;
                        //product_cost = 255;
                    }
                    else if($(".result-selected").html("Issue and create documentation transmittal for drawings"))
                    {
                        //(RTV Drawing Manager) = .5
                        //costs = 0.5;
                       // product_cost = 255;
                    }
                    else if($(".result-selected").html("Create and publish digital files to an FTP site"))
                    {
                        //(Xporter Pro)  = .5
                        //costs = 0.5;
                        //product_cost = 49;
                    }
                    else if($(".result-selected").html("Create and update shared parameters "))
                    {
                        //(RTV Shared Parameter Manager) = .15
                        //costs = 0.15;
                       // product_cost = 99.50;
                    }
                    else if($(".result-selected").html("Search and create manufactures specific paint materials"))
                    {
                        //(RTV Paint) = .1
                       // costs = 0.1;
                       // product_cost = 9.99;
                    }
                    else if($(".result-selected").html("Create furniture and fittings schedules"))
                    {
                        //(RTV Reporter) = .65
                    //var    costs = 0.65;
                    //var    product_cost = 75;
                        
                        var qty = $("#input_4_11").val();
                    var hourly = $("#input_4_14").val();
                    var time_taken = $("#input_4_35").val();
                    
                    var time_saved = ((qty * time_taken) - ((qty * time_taken)  * costs))/60;
                    
              
                    var money_saved = time_saved * hourly;
                    
                    money_saved = money_saved.toFixed(2);
  
                    $('#input_4_20').val(time_saved);
                    
                    
                    //Money Saved---------------------------------------------------------------
                    //(Time Saved / 60) * Hourly Rate
                    $('#input_4_22').val(money_saved);
                    
                    //RTV Product Cost----------------------------------------------------------
                    $('#input_4_24').val(product_cost);
                    
                    //Automatic ROI------------------------------------------------------------
                    $('#input_4_23').val(money_saved - product_cost);
                    }
                    //Time Saved-----------------------------------------------------------------
                    /*
                    ((Number of items to Automate *Time taken )*  Hourly Rate/60 -  (Number of items to Automate * Field 1 (these values are below again))
                    */
                    
                }
                else
                {
                    alert("Please go to the top of the page and select a package.");
                }
            }
            else
            {
                //Failed
            }    
        }
        
    });

</script>

can you help me with what I am doing wrong?
thank you in advance..
 
even though I choose the other products from the drop down it still uses the code from the first product in the select box:

That means you never actually update the variable you are using for the calculation.

Chris.

Indifference will be the downfall of mankind, but who cares?
Time flies like an arrow, however, fruit flies like a banana.
Webmaster Forum
 
Thanks Chris for the reply... so how would I update the variable is it the fact that I have the if clause?is there something I am missing that I can add that would update it?
Cheers
 
No idea, I don't do jQuery, never yet found a need to have a large chunk of overhead loaded just for a few functions that I already have in my code library. :)

Chris.

Indifference will be the downfall of mankind, but who cares?
Time flies like an arrow, however, fruit flies like a banana.
Webmaster Forum
 
Hi

swazisteve, I would give a try to correct your code, but I have no time to reproduce the HTML document your script depends on. So maybe if you post the relevant HTML part too...

Feherke.
feherke.ga
 
Hey Feherke, thank you!
code below:
HTML:
<form method="post" enctype="multipart/form-data" id="gform_4" action="/roi-calc-test/">
                        <div class="gform_heading">
                            <h3 class="gform_title">ROI Calculator - Copy 1</h3>
                            <span class="gform_description"></span>
                        </div>
                        <div class="gform_body">
                            <ul id="gform_fields_4" class="gform_fields top_label description_below"><li id="field_4_2" class="gfield    product-slide  gfield_html gfield_html_formatted gfield_no_follows_desc"><img src="[URL unfurl="true"]http://www.rtvtools.com/wp-content/uploads/2013/12/RTV-CALCULATOR-ICONS.jpg.jpeg"[/URL] alt="calculator-icon-hero" class="aligncenter size-full wp-image-2689" style="margin-bottom:15px" height="155" width="822"></li><li id="field_4_1" class="gfield    process_select"><label class="gfield_label" for="input_4_1">Select existing process to automate</label><div class="ginput_container"><select style="display: none;" name="input_1" id="input_4_1" onchange="gf_apply_rules(4,[4,34,6,7,8,9]);" class="medium gfield_select chzn-done" tabindex="-1"><option value="Select...">Select...</option><option value="Printing drawing">Printing drawing</option><option value="Creating digital files">Creating digital files</option><option value="Combined printing and creating digital files">Combined printing and creating digital files</option><option value="Update title blocks / drawing sheets">Update title blocks / drawing sheets</option><option value="Adding and updating revisions on title blocks / drawing sheets">Adding and updating revisions on title blocks / drawing sheets</option><option value="Issue and create documentation transmittal for drawings">Issue and create documentation transmittal for drawings</option><option value="Create and publish digital files to an FTP site">Create and publish digital files to an FTP site</option><option value="Create and update shared parameters ">Create and update shared parameters </option><option value="Search and create manufactures specific paint materials">Search and create manufactures specific paint materials</option><option value="Create furniture and fittings schedules">Create furniture and fittings schedules</option></select><div title="" style="width: 442px;" class="chzn-container chzn-container-single" id="input_4_1_chzn"><a href="javascript:void(0)" class="chzn-single" tabindex="-1"><span>Select...</span><div><b></b></div></a><div class="chzn-drop" style="left: -9000px; width: 440px; top: 38px;"><div class="chzn-search"><input tabindex="1" style="width: 405px;" autocomplete="off" type="text"></div><ul class="chzn-results"><li id="input_4_1_chzn_o_0" class="active-result result-selected" style="">Select...</li><li id="input_4_1_chzn_o_1" class="active-result" style="">Printing drawing</li><li id="input_4_1_chzn_o_2" class="active-result" style="">Creating digital files</li><li id="input_4_1_chzn_o_3" class="active-result" style="">Combined printing and creating digital files</li><li id="input_4_1_chzn_o_4" class="active-result" style="">Update title blocks / drawing sheets</li><li id="input_4_1_chzn_o_5" class="active-result" style="">Adding and updating revisions on title blocks / drawing sheets</li><li id="input_4_1_chzn_o_6" class="active-result" style="">Issue and create documentation transmittal for drawings</li><li id="input_4_1_chzn_o_7" class="active-result" style="">Create and publish digital files to an FTP site</li><li id="input_4_1_chzn_o_8" class="active-result" style="">Create and update shared parameters </li><li id="input_4_1_chzn_o_9" class="active-result" style="">Search and create manufactures specific paint materials</li><li id="input_4_1_chzn_o_10" class="active-result" style="">Create furniture and fittings schedules</li></ul></div></div></div></li><li id="field_4_30" class="gfield    blue-arrow-down  gfield_html gfield_html_formatted gfield_no_follows_desc"><img src="[URL unfurl="true"]http://www.rtvtools.com/wp-content/themes/rtv-tools/images/roi-calc/blue-arrow-down.png"[/URL] alt="rtv-reporter" style="vertical-align:text-bottom; width:100px;margin-top:2px"></li><li id="field_4_3" class="gfield    product_suggest  gfield_html gfield_html_formatted gfield_no_follows_desc"><h2 style="color:#fff;padding-top:40px;">Suggested RTV Tools automation software</h2>
<p style="color:#fff;font-size:15px;padding-left:20px;padding-right:20px">RTV Tools research shows that 80% of the customers who purchased one of ourproducts, saw a 100% return on their investment within the first week.</p>
<img src="[URL unfurl="true"]http://www.rtvtools.com/wp-content/themes/rtv-tools/images/roi-calc/dots-arrows.png"[/URL] alt="product-arrow" style="width:44px;height:94px"></li><li id="field_4_4" class="gfield    product_actual  gfield_html gfield_html_formatted gfield_no_follows_desc" style="display:none;"><img src="[URL unfurl="true"]http://www.rtvtools.com/wp-content/themes/rtv-tools/images/roi-calc/rtv-xporter.png"[/URL] alt="rtv-reporter" style="margin:10px; vertical-align:text-top;"><img src="[URL unfurl="true"]http://www.rtvtools.com/wp-content/themes/rtv-tools/images/roi-calc/rtv-xporter-pro.png"[/URL] alt="rtv-reporter" style="margin:10px; vertical-align:text-top;"><img src="[URL unfurl="true"]http://www.rtvtools.com/wp-content/themes/rtv-tools/images/roi-calc/rtv-drawing-manager.png"[/URL] alt="rtv-reporter" style="margin:10px; vertical-align:text-top;"></li><li id="field_4_34" class="gfield    product_actual  gfield_html gfield_html_formatted gfield_no_follows_desc" style="display:none;"><img src="[URL unfurl="true"]http://www.rtvtools.com/wp-content/themes/rtv-tools/images/roi-calc/rtv-xporter-pro.png"[/URL] alt="rtv-reporter" style="margin:10px; vertical-align:text-top;"></li><li id="field_4_6" class="gfield    product_actual  gfield_html gfield_html_formatted gfield_no_follows_desc" style="display:none;"><img src="[URL unfurl="true"]http://www.rtvtools.com/wp-content/themes/rtv-tools/images/roi-calc/rtv-drawing-manager.png"[/URL] alt="rtv-reporter" style="margin:10px; vertical-align:text-top;"></li><li id="field_4_7" class="gfield    product_actual  gfield_html gfield_html_formatted gfield_no_follows_desc" style="display:none;"><img src="[URL unfurl="true"]http://www.rtvtools.com/wp-content/themes/rtv-tools/images/roi-calc/rtv-reporter.png"[/URL] alt="rtv-reporter" style="margin:10px; vertical-align:text-top;"></li><li id="field_4_8" class="gfield    product_actual  gfield_html gfield_html_formatted gfield_no_follows_desc" style="display:none;"><img src="[URL unfurl="true"]http://www.rtvtools.com/wp-content/themes/rtv-tools/images/roi-calc/rtv-shared-parameter-manager.png"[/URL] alt="rtv-reporter" style="margin:10px; vertical-align:text-top;">
</li><li id="field_4_9" class="gfield    product_actual  gfield_html gfield_html_formatted gfield_no_follows_desc" style="display:none;"><img src="[URL unfurl="true"]http://www.rtvtools.com/wp-content/themes/rtv-tools/images/roi-calc/rtv-paint.png"[/URL] alt="rtv-reporter" style="margin:10px; vertical-align:text-top;"></li><li id="field_4_29" class="gfield    white-arrow-down blue-background  gfield_html gfield_html_formatted gfield_no_follows_desc"><img src="[URL unfurl="true"]http://www.rtvtools.com/wp-content/themes/rtv-tools/images/roi-calc/down-arrow.png"[/URL] alt="rtv-reporter" style="vertical-align:text-bottom; width:100px;margin-top:2px"></li><li id="field_4_5" class="gfield      gfield_html gfield_html_formatted gfield_no_follows_desc"><h2 style="text-align:center;margin-top:40px">Calculate Your Costs</h2>
<p style="text-align:center;font-size:15px">Our research indicates that the biggest cost to AEC businesses is labour.</p></li><li id="field_4_10" class="gfield    product-input-items  gfield_html  gfield_no_follows_desc"><img src="[URL unfurl="true"]http://www.rtvtools.com/wp-content/themes/rtv-tools/images/roi-calc/items.png"[/URL] alt="rtv-items" style="margin:10px; vertical-align:text-top;"></li><li id="field_4_13" class="gfield    product-hourly-rate  gfield_html  gfield_no_follows_desc"><img src="[URL unfurl="true"]http://www.rtvtools.com/wp-content/themes/rtv-tools/images/roi-calc/hourly-rate.png"[/URL] alt="rtv-hourly-rate" style="margin:10px; vertical-align:text-top;"></li><li id="field_4_16" class="gfield  gsection  blank-section-break"><h2 class="gsection_title"></h2></li><li id="field_4_11" class="gfield    product-input-items"><label class="gfield_label" for="input_4_11">Number of items to be automated</label><div class="ginput_container"><input name="input_11" id="input_4_11" value="" class="medium" tabindex="2" type="text"></div></li><li id="field_4_35" class="gfield"><label class="gfield_label" for="input_4_35">Time taken</label><div class="ginput_container"><input name="input_35" id="input_4_35" value="" class="medium" tabindex="3" type="text"></div></li><li id="field_4_14" class="gfield    product-hourly-rate"><label class="gfield_label" for="input_4_14">Hourly Rate</label><div class="ginput_container"><input name="input_14" id="input_4_14" value="" class="medium" tabindex="4" type="text"></div></li><li id="field_4_17" class="gfield  gsection  blank-section-break"><h2 class="gsection_title"></h2></li><li id="field_4_12" class="gfield    product-input-items  gfield_html  gfield_no_follows_desc"><p style="text-align:center;font-size:15px; width: 50%; margin:auto">Enter the total number of items to be automated in a single process</p>
</li><li id="field_4_15" class="gfield    product-hourly-rate  gfield_html  gfield_no_follows_desc"><p style="text-align:center;font-size:15px; width: 50%; margin:auto">Enter the cost as the billable/cost value per hour. For example: for a billable rate of $65/hr enter 65.</p></li><li id="field_4_31" class="gfield    purple-arrow-down  gfield_html gfield_html_formatted gfield_no_follows_desc"><img src="[URL unfurl="true"]http://www.rtvtools.com/wp-content/themes/rtv-tools/images/roi-calc/purple-arrow-down.png"[/URL] alt="rtv-reporter" style="vertical-align:text-bottom; width:100px;margin-top:2px"></li><li id="field_4_18" class="gfield    product_automated  gfield_html  gfield_no_follows_desc"><h2 style="color:#fff;padding-top:40px;">Automated ROI</h2>
<p style="color:#fff;font-size:15px">Automation can help dramatically improve the efficiency of your project teams.</p></li><li id="field_4_20" class="gfield    product-time-saved"><label class="gfield_label" for="input_4_20">Estimated Time Saved</label><div class="ginput_container"><input name="input_20" id="input_4_20" value="" class="medium" tabindex="5" type="text"></div></li><li id="field_4_21" class="gfield    product-roi-image  gfield_html  gfield_no_follows_desc"><img src="[URL unfurl="true"]http://www.rtvtools.com/wp-content/themes/rtv-tools/images/roi-calc/roi.png"[/URL] alt="rtv-reporter" style="margin:10px; vertical-align:text-top;"></li><li id="field_4_26" class="gfield  gsection  blank-section-break-purple"><h2 class="gsection_title"></h2></li><li id="field_4_22" class="gfield    product-money-saved"><label class="gfield_label" for="input_4_22">Estimated Money Saved</label><div class="ginput_container"><input name="input_22" id="input_4_22" value="" class="medium" tabindex="6" type="text"></div></li><li id="field_4_23" class="gfield    product-auto-roi"><label class="gfield_label" for="input_4_23">Estimated Automation ROI</label><div class="ginput_container"><input name="input_23" id="input_4_23" value="" class="medium" tabindex="7" type="text"></div></li><li id="field_4_27" class="gfield  gsection  blank-section-break-purple"><h2 class="gsection_title"></h2></li><li id="field_4_24" class="gfield    product-rtv-cost"><label class="gfield_label" for="input_4_24">RTV Product Cost</label><div class="ginput_container"><input name="input_24" id="input_4_24" value="" class="medium" tabindex="8" type="text"></div></li><li id="field_4_25" class="gfield    product-rtv-info  gfield_html  gfield_no_follows_desc"><p style="color:#fff;font-size:15px; width: 50%; margin: auto;"></p></li><li id="field_4_28" class="gfield    white-arrow-down purple-background  gfield_html gfield_html_formatted gfield_no_follows_desc"><img src="[URL unfurl="true"]http://www.rtvtools.com/wp-content/themes/rtv-tools/images/roi-calc/down-arrow.png"[/URL] alt="rtv-reporter" style="vertical-align:text-bottom; width:100px;margin-top:2px"></li><li id="field_4_19" class="gfield  gsection  blank-section-break"><h2 class="gsection_title"></h2></li><li id="field_4_32" class="gfield      gfield_html gfield_html_formatted gfield_no_follows_desc"><h2 style="text-align:center;margin-top:40px">Learn more about automation</h2>
<p style="text-align:center;font-size:15px">RTV Tools automation has the ability to transform your existing business processes. Complete the field below, and we’ll contact you to show you exactly how automation can take your business to a whole new level.</p></li><li id="field_4_33" class="gfield    product-email           gfield_contains_required"><label class="gfield_label" for="input_4_33">Your Email Address<span class="gfield_required">*</span></label><div class="ginput_container"><input name="input_33" id="input_4_33" value="" class="medium" tabindex="9" type="text"></div></li>
                            </ul></div>
        <div class="gform_footer top_label"> <input id="gform_submit_button_4" class="button gform_button" value="Submit" tabindex="10" onclick="if(window[&quot;gf_submitting_4&quot;]){return false;}  window[&quot;gf_submitting_4&quot;]=true; " type="submit">
            <input class="gform_hidden" name="is_submit_4" value="1" type="hidden">
            <input class="gform_hidden" name="gform_submit" value="4" type="hidden">
            <input class="gform_hidden" name="gform_unique_id" value="" type="hidden">
            <input class="gform_hidden" name="state_4" value="WyJhOjA6e30iLCIwYzZjMTMxNThkYWY5OTUzNDA0YTExOWNjMmZlMzM2NSJd" type="hidden">
            <input class="gform_hidden" name="gform_target_page_number_4" id="gform_target_page_number_4" value="0" type="hidden">
            <input class="gform_hidden" name="gform_source_page_number_4" id="gform_source_page_number_4" value="1" type="hidden">
            <input name="gform_field_values" value="" type="hidden">
            
        </div>
                </form>
 
Hi

I am lost. Does that need more JavaScript or other libraries, for example jQuery UI or something ? It sends me to the top of the page to select something, but currently I see only a non-functional link and a plain unordered list.


Feherke.
feherke.ga
 
Hi

Much better this way, however you introduced some new errors in the live version : in 2 cases the [tt]if[/tt] is missing ( the ones for the "Creating digital files" and "Create furniture and fittings schedules" branches ).

Your main problem seem to be the condition. This returns a jQuery object, which in terms of JavaScript will always evaluate to [tt]true[/tt] :
JavaScript:
[gray]// current, syntactically correct, logically wrong[/gray]
                    [b]if[/b]($([green][i]".result-selected"[/i][/green]).html([green][i]"Printing drawing"[/i][/green]))

[gray]// proposed[/gray]
                    [b]if[/b]($([green][i]".result-selected"[/i][/green]).html() == [green][i]"Printing drawing"[/i][/green])

The current code always sets all selected nodes' [tt]innerHTML[/tt] to the given string literal and return the object so you can chain further jQuery method calls.
The proposed code gets the first selected node's [tt]innerHTML[/tt] and compares it to the given string literal.


Feherke.
feherke.ga
 
Hey mate. absolutely superb! worked a treat.
funny how just a simple == can make the difference!
 
Hey Feherke
again thanks for your help above... they have introducted another facet to this...
what they want is if the first prooduct in the slect box is chosen a second select box appears.
I have done that part and the conditions attributed to that..
what I am having trouble with is the JS on the if == && for example
Code:
  else if($(".result-selected").html() == "Printing drawing" &&  $(".result-selected").html() == "RTV Xporter")

if you see the code below you will see what I am doing.
also the page is still the same I have just added a second select box in..
hope you can help!
cheers
Code:
  jQuery(document).ready(function($) {
        //Items
        $("#input_4_11").on('keyup', do_maths);
        //time taken
        $("#input_4_35").on('keyup', do_maths);
        //Hourly Rate
        $("#input_4_14").on('keyup', do_maths);
         
                
        
               function do_maths()
        {
            var costs;
            var product_cost;

           if($.isNumeric($('#input_4_11').val()) && $.isNumeric($('#input_4_35').val()) && $.isNumeric($('#input_4_14').val())) 
            {
            
            
                if($(".result-selected").html() !== "Select...")
                {
                    if($(".result-selected").html() == "Printing drawing")
                    {
                        //(RTV Xporter, Xporter PRO and Drawing Manager)  = .25
                        costs = 0.25;
                        product_cost = 9.99;
                    }
                    else if($(".result-selected").html() == "Printing drawing" &&  $(".result-selected").html() == "RTV Xporter")
                    {
                        //(RTV Xporter, Xporter PRO and Drawing Manager)  = .25
                        costs = 0.25;
                        product_cost = 9.99;
                    }
                    else if($(".result-selected").html() == "RTV Xporter Pro")
                    {
                        //(RTV Xporter, Xporter PRO and Drawing Manager)  = .25
                        costs = 0.25;
                        product_cost = 49;
                    }
                    else if($(".result-selected").html() == "RTV Drawing Manager")
                    {
                        //(RTV Xporter, Xporter PRO and Drawing Manager)  = .25
                        costs = 0.25;
                        product_cost = 255;
                    }
                    else if($(".result-selected").html() == "Creating digital files" && "RTV Xporter")
                    {
                        //(RTV Xporter, Xporter PRO and Drawing Manager) = .25
                        costs = 0.25;
                        product_cost = 9.99;
                    }
                     else if($(".result-selected").html() == "Creating digital files" && "RTV Xporter Pro")
                    {
                        //(RTV Xporter, Xporter PRO and Drawing Manager) = .25
                        costs = 0.25;
                        product_cost = 49;
                    }
                     else if($(".result-selected").html() == "Creating digital files" && "RTV Drawing Manager")
                    {
                        //(RTV Xporter, Xporter PRO and Drawing Manager) = .25
                        costs = 0.25;
                        product_cost = 255;
                    }
                    else if($(".result-selected").html() == "Combined printing and creating digital files")
                    {
                        //(Drawing Manager) = .5
                        costs = 0.5;
                        product_cost = 255;
                        
                    }
                    else if($(".result-selected").html() == "Update title blocks / drawing sheets")
                    {
                        //(RTV Drawing Manager) = .1
                         costs = 0.1;
                         product_cost = 255;
                    }
                    else if($(".result-selected").html() == "Adding and updating revisions on title blocks / drawing sheets")
                    {
                        //(RTV Drawing Manager) = .25
                        costs = 0.25;
                        product_cost = 255;
                    }
                    else if($(".result-selected").html() == "Issue and create documentation transmittal for drawings")
                    {
                        //(RTV Drawing Manager) = .35
                        costs = 0.35;
                        product_cost = 255;
                    }
                    else if($(".result-selected").html() == "Create and publish digital files to an FTP site")
                    {
                        //(Xporter Pro)  = .25
                        costs = 0.25;
                        product_cost = 49;
                    }
                    else if($(".result-selected").html() == "Create and update shared parameters")
                    {
                        //(RTV Shared Parameter Manager) = .15
                        costs = 0.15;
                        product_cost = 135;
                    }
                    else if($(".result-selected").html() == "Search and create manufactures specific paint materials")
                    {
                        //(RTV Paint) = .1
                        costs = 0.1;
                        product_cost = 9.99;
                    }
                    else if($(".result-selected").html() == "Create furniture and fittings schedules")
                    {
                        //(RTV Reporter) = .65
                        costs = 0.65;
                        product_cost = 75;
                    }
                    else if($(".result-selected").html() == "Create Bill of Materials Schedules")
                    {
                        //(RTV Reporter) = .65
                        costs = 0.65;
                        product_cost = 75;
                    }
                    //Time Saved-----------------------------------------------------------------
                    /*
                    (Number of items to Automate * Hourly Rate)  -  (Number of items to Automate * Field 1 (these values are below again))
                    */
                    var qty = $("#input_4_11").val();
                    var hourly = $("#input_4_14").val();
                    var time_taken = $("#input_4_35").val();
                    
                    var time_saved = ((qty * time_taken) - ((qty * time_taken)  * costs))/60;
                    var money_saved = time_saved * hourly;
                    
                    money_saved = money_saved.toFixed(2);
  
                    $('#input_4_20').val(time_saved);
                    
                    
                    
                    //Money Saved---------------------------------------------------------------
                    //(Time Saved / 60) * Hourly Rate
                    $('#input_4_22').val(money_saved);
                    
                    //RTV Product Cost----------------------------------------------------------
                    $('#input_4_24').val(product_cost);
                    
                    //Automatic ROI------------------------------------------------------------
                    $('#input_4_23').val(money_saved - product_cost);
                    
                    
                 
                }
                else
                {
                    alert("SELECT FAIL");
                }
            }
            else
            {
                //Failed
            }    
        }
        
    });

 
Hi

Given that both selects have the same [tt]class[/tt], jQuery will match both and extract the first one's [tt]innerHTML[/tt] in both subexpressions.

Any of these should solve it :
Code:
[gray]// minimal change in your code[/gray]
[b]else[/b] [b]if[/b]($([green][i]".result-selected"[/i][/green]).html() == [green][i]"Printing drawing"[/i][/green] && $([green][i]".result-selected"[/i][/green])[highlight][1][/highlight].html() == [green][i]"RTV Xporter"[/i][/green]) 

[gray]// same as above, you may find it more readable[/gray]
[b]else[/b] [b]if[/b]($([green][i]".result-selected"[/i][/green]).html() == [green][i]"Printing drawing"[/i][/green] && $([green][i]".result-selected"[/i][/green])[highlight].last()[/highlight].html() == [green][i]"RTV Xporter"[/i][/green]) 

[gray]// narrowing the expression[/gray]
[b]else[/b] [b]if[/b]($([green][i]"[highlight]#input_4_1_chzn[/highlight] .result-selected"[/i][/green]).html() == [green][i]"Printing drawing"[/i][/green] && $([green][i]"[highlight]#input_4_40_chzn[/highlight] .result-selected"[/i][/green]).html() == [green][i]"RTV Xporter"[/i][/green])

I not know much about how that document itself is generated. While the above solutions should work for now, they may become unusable if the document's structure changes.


Feherke.
feherke.ga
 
ahhh... thank you will try it out and get back to you!
I take it the other selects will stay the same to work properly?
 
Hi

Oops, a bug in the first alternative. If you pick an element by index, you get a node, not a jQuery object, so will not have [tt]html()[/tt] method, just [tt]innerHTML[/tt] property :
Code:
[b]else[/b] [b]if[/b]($([green][i]".result-selected"[/i][/green]).html() == [green][i]"Printing drawing"[/i][/green] && $([green][i]".result-selected"[/i][/green])[1].[highlight]innerHTML[/highlight] == [green][i]"RTV Xporter"[/i][/green])

swazisteve said:
I take it the other selects will stay the same to work properly?
Yes. As mentioned, the [tt]html()[/tt] method returns the first matching element's content. As I understand, in all other cases you need to test against the first select, so you will get exactly what you need.


Feherke.
feherke.ga
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top