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.
Page 1 of 2 12 LastLast
Results 1 to 15 of 17
  1. #1
    New Coder Limey10's Avatar
    Join Date
    Sep 2009
    Location
    Malaysia
    Posts
    61
    Thanks
    9
    Thanked 0 Times in 0 Posts

    Price quote generator - here I go again :-)

    Hi all. I hope that everyone is fine and doing well.

    I am hoping for some help with my price generator (which was produced with a great deal of help from the forum members here); so I am here again with my begging face on .


    The generator works spectacularly well, but I need to provide users with an additional output; I will try to explain as best I can.


    Clients currently input a figure that represents the number of words in a document that need proofreading, editing, or translating. They then select one of three turnaround time packages for each discipline, and a price is produced.

    Each package has a certain number of words that can be edited within a certain number of days. For example, although I can "proofread" 8000 words in two days, I can only "translate" 5000 words two days. This doesn't restrict them from sending more than 8000 or 5000 words, it just means that depending on which package they select, the turnaround time will be different. Does that make sense?

    So I need a way of telling customers how long it will take to edit their document, preferably rounded up to the nearest single day or half day.

    So lets say John Doe submits 12000 words for proofreading, he wants to use my 2 days per 8000 words turnaround package. It will therefore take 12000/8000 x 2 = 3 days. It obviously gets trickier when obscure numbers are used (like 11534 words etc.)

    So this is hard enough for me to explain, let alone work out how to code it.

    This has been a major drawback over the past few years, so I'm really hoping that there is someone out there who likes this kind of challenge. I would be very grateful if there is :-)

    To see this code in action as it stands, please go to www.grammarproofing.com

    Thanks in advance, Phil



    Code:
    <!--quote generator -->
    <script type="text/javascript">
    var exchangeRates = [1, 0.31, 0.206, 0.250];
    function update(){
       var er = exchangeRates[document.getElementById("Currency").value];// selected exchange rate
       var price = document.getElementById("Package").value;
       var words = document.getElementById("words").value;
       if (words != "") {
          words = parseInt(words);
          if (isNaN (words)) {
             alert ("Please enter the number of words in figures");
             document.getElementById("words").value = "";
             return false;
          }
       }
       var wordsOver2000 = words-2000;
       if (wordsOver2000 <0) {wordsOver2000 = 0}
       words = words - wordsOver2000;
       var Tprice = (((price * words) + (price * 1.00 * wordsOver2000))*er).toFixed(2);
       document.getElementById("Totprice").value = Tprice;
       document.getElementById("Totprice2").innerHTML = "Your Quote Total Is: " + Tprice
    }
    </script>
    <!--end quote generator -->


    Code:
    <!--start quote generator -->
    <div class="quote" id="quote"><br>
      <img src="images/comodo-positivessl-.png" alt="SSL Seal" width="102" height="103" align="left">INSTANT QUOTE - All available services<br /><br />
    
    How many words are in your document?<br />
       <input type="text" id="words" onchange="update()" value="" /><br /><br />
      Select the package that best describes your needs
      <select name="Package" id = "Package" style="width:420" onchange = "update()">
        <option value="0.06">STUDENT PROOFREADING - 48 HOURS (PER 8,000 WORDS)</option>
        <option value="0.05" selected="selected">STUDENT PROOFREADING - 4 DAYS (PER 8,000 WORDS)</option>
        <option value="0.04">STUDENT PROOFREADING - 6 DAYS (PER 8,000 WORDS)</option>
        <option value="0">---------------------------------------------------------------------------------------------</option>
        <option value="0.09">BUSINESS PROOFREADING - 48 HOURS (PER 5,000 WORDS)</option>
        <option value="0.08">BUSINESS PROOFREADING - 3 DAYS (PER 5,000 WORDS)</option>
        <option value="0.07">BUSINESS PROOFREADING - 5 DAYS (PER 5,000 WORDS)</option>
        <option value="0">---------------------------------------------------------------------------------------------</option>
        <option value="0.11">REWORDING/EDITING - 48 HOURS (PER 5,000 WORDS)</option>
        <option value="0.10">REWORDING/EDITING - 5 DAYS (PER 5,000 WORDS)</option>
        <option value="0.09">REWORDING/EDITING - 8 DAYS (PER 5,000 WORDS)</option>
        <option value="0">---------------------------------------------------------------------------------------------</option>
        <option value="0.11">TRANSLATION - 48 HOURS PER 5,000 WORDS</option>
        <option value="0.10">TRANSLATION - 5 DAYS PER 5,000 WORDS</option>
        <option value="0.09">TRANSLATION - 7 DAYS PER 5,000 WORDS</option>
      </select><br /><br />
      
    Your total fee will be 
      
    <input type = "text" id = "Totprice" readonly /> 
    <select name="Currency" id = "Currency" onchange = "update()">
        <option value="0" selected="selected">MYR</option>
        <option value="1">USD</option>
        <option value="2">GBP</option>
        <option value="3">EURO</option>
      </select><br /><br />
    
    </div>
    <!--end quote generator -->
    "I'm still smiling because they haven't found the bodies yet.....muhahaha (evil laugh)"
    GrammarProofing

  • #2
    Senior Coder jmrker's Avatar
    Join Date
    Aug 2006
    Location
    FL
    Posts
    3,091
    Thanks
    38
    Thanked 498 Times in 492 Posts
    You will need to check each selection for formula correctness,
    but this should round your wordcount up depending on the number of words
    to process in a particular day.

    Code:
    <!DOCTYPE html>
    <html lang="en">
    <head>
    <meta charset="UTF-8" />
    
    <title> HTML5 page </title>
    <style type="text/css">
     #Totprice2 { font-size:2em; color:red; }
    </style>
    
    </head>
    <body>
    
    <!--start quote generator -->
    <div class="quote" id="quote"><br>
      <img src="images/comodo-positivessl-.png" alt="SSL Seal" width="102" height="103" align="left">INSTANT QUOTE - All available services<br /><br />
    
    How many words are in your document?<br />
      <input type="text" id="words" value="" />
      <button onclick="update()">Calculate Fees</button>
      <br /><br />
      Select the package that best describes your needs <br>
      <select name="Package" id = "Package" style="width:420" onchange = "update()">
        <optgroup label="Student Proofreading">
          <option value="0.06">STUDENT PROOFREADING - 48 HOURS (PER 8,000 WORDS)</option>
          <option value="0.05" selected="selected">STUDENT PROOFREADING - 4 DAYS (PER 8,000 WORDS)</option>
          <option value="0.04">STUDENT PROOFREADING - 6 DAYS (PER 8,000 WORDS)</option>
        </optgroup>
        <optgroup label="Business Proofreading">
         <option value="0.09">BUSINESS PROOFREADING - 48 HOURS (PER 5,000 WORDS)</option>
         <option value="0.08">BUSINESS PROOFREADING - 3 DAYS (PER 5,000 WORDS)</option>
         <option value="0.07">BUSINESS PROOFREADING - 5 DAYS (PER 5,000 WORDS)</option>
        </optgroup>
        <optgroup label="Rewording / Edition">
          <option value="0.11">REWORDING/EDITING - 48 HOURS (PER 5,000 WORDS)</option>
          <option value="0.10">REWORDING/EDITING - 5 DAYS (PER 5,000 WORDS)</option>
          <option value="0.09">REWORDING/EDITING - 8 DAYS (PER 5,000 WORDS)</option>
        </optgroup>
        <optgroup label="Translation">
          <option value="0.11">TRANSLATION - 48 HOURS PER 5,000 WORDS</option>
          <option value="0.10">TRANSLATION - 5 DAYS PER 5,000 WORDS</option>
          <option value="0.09">TRANSLATION - 7 DAYS PER 5,000 WORDS</option>
        </optgroup>
      </select><br /><br />
      
    <div id="Totprice2"></div>
      
    <input type = "text" id = "Totprice" readonly /> 
    <select name="Currency" id = "Currency" onchange="update()">
        <option value="0" selected="selected">MYR</option>
        <option value="1">USD</option>
        <option value="2">GBP</option>
        <option value="3">EURO</option>
      </select><br /><br />
    
    </div>
    <!--end quote generator -->
    
    <!--quote generator -->
    <script type="text/javascript">
    var exchangeRates = [1, 0.31, 0.206, 0.250];
    function update(){
       var price = document.getElementById("Package").value;
       var words = document.getElementById("words").value;
       if (words != "") {
          words = parseInt(words);
          if (isNaN (words)) {
             alert ("Please enter the number of words in figures");
             document.getElementById("words").value = "";
             return false;
          }
       }
       var er = exchangeRates[document.getElementById("Currency").value];// selected exchange rate
       if (er == 1) {
         alert('MYR not selected');  return false;
       }
    
    /* following not currently used
       var wordsOver2000 = words-2000;
       if (wordsOver2000 <0) {wordsOver2000 = 0}
       words = words - wordsOver2000;
    */
    
    var perWord = 5000;                                                            // most common processing rate
    if (document.getElementById('Package').selectedIndex < 3) { perWord = 8000; }  // student discount
    var wordRange = Math.floor(words/perWord)+1;                                   // form amount to process per day (1 day minimum)
    words = wordRange * perWord;                                                   // adjust word count for calculations
    alert('# of words for calculation purposes: '+words);  // for testing only
       var Tprice = (price * words*er).toFixed(2);
    
    //   var Tprice = (((price * words) + (price * 1.00 * wordsOver2000))*er).toFixed(2);
       document.getElementById("Totprice").value = Tprice;
       document.getElementById("Totprice2").innerHTML = "Your Quote Total Is: " + Tprice
    }
    </script>
    <!--end quote generator -->
    
    
    </body>
    </html>
    Some minor formatting changes to the selectboxes
    but the major change is highlighted in red.

    I put in a calculate button because the selectboxes only modify the total when a change occurs.
    With the button, the user can recalculate without changing the selections if only the # words is modified.

  • #3
    New Coder Limey10's Avatar
    Join Date
    Sep 2009
    Location
    Malaysia
    Posts
    61
    Thanks
    9
    Thanked 0 Times in 0 Posts
    Hi Jmrker

    Thank you for your response.

    I don't think I explained my problem properly (sorry). I am looking for the generator to calculate the number of days that it will take to edit the client's fixed number of words when they select a particular package (which has constraints of only a certain number of words can be edited per individual package)

    Price quote generator - here I go again :-)-example1.jpg

    Price quote generator - here I go again :-)-example2.jpg

    As you can see, the same number of words using different packages produces different return times.

    I feel bad because you spent precious time on that code (apologies).

    Regards, Phil
    "I'm still smiling because they haven't found the bodies yet.....muhahaha (evil laugh)"
    GrammarProofing

  • #4
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,869
    Thanks
    79
    Thanked 4,418 Times in 4,383 Posts
    So you need to encapsulate the needed information in the <select>'s <option>s.

    Because two given <option>s can have the same value, you can't tell by the value, alone, which option means which translation/edit/proofread was chosen.

    So what you could do is have a separate array that has your needed info, matching each option by number (0 through n) with a description in a form that you can use to drive the number-of-days calculation.

    *OR* you could put that same info directly into the <option>s' values!

    Something like this:
    Code:
         <option value="3;5000;0.08">BUSINESS PROOFREADING - 3 DAYS (PER 5,000 WORDS)</option>
    Now, when you get the value from the <select>, you simply do:
    Code:
    var info = document.getElementById("words").value.split(";");
    var numberOfDays = +info[0];
    var numberOfWords = +info[1];
    var words = +info[2]; // your original words value
    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.

  • #5
    New Coder Limey10's Avatar
    Join Date
    Sep 2009
    Location
    Malaysia
    Posts
    61
    Thanks
    9
    Thanked 0 Times in 0 Posts
    Hi Old Pedant

    I kind of get the first bit of code (you assign 3 different values to each option), but I really don't understand the second bit of code, where i place it or how i produce a nice little box with a whole number of days in it.

    Did I mention that I don't really know a lot about code? (I imagine by this stage, I no longer need to :-)

    Regards, Phil
    "I'm still smiling because they haven't found the bodies yet.....muhahaha (evil laugh)"
    GrammarProofing

  • #6
    Senior Coder xelawho's Avatar
    Join Date
    Nov 2010
    Posts
    2,980
    Thanks
    56
    Thanked 557 Times in 554 Posts
    another approach would be to have an array that specifies the number of words per day to match the select options (kind of clunky to update, but if those numbers don't change that shouldn't be a worry). The you just divide the total words by that amount and round up to the nearest whole number. The below code uses you html as posted in #1:

    Code:
    <script type="text/javascript">
    
    function update(){
    	var exchangeRates = [1, 0.31, 0.206, 0.250];
    	var wpd=[4000,2000,1334,0,2500,1667,1000,0,2500,1000,625,0,2500,1000,715];
       var er = exchangeRates[document.getElementById("Currency").value];// selected exchange rate
       var price = document.getElementById("Package").value;
       var words = document.getElementById("words").value;
       var oneday=wpd[document.getElementById("Package").selectedIndex];
       var days=Math.ceil(words/oneday);
       alert(days+" days turnaround");
       if (words != "") {
          words = parseInt(words);
          if (isNaN (words)) {
             alert ("Please enter the number of words in figures");
             document.getElementById("words").value = "";
             return false;
          }
       }
       var wordsOver2000 = words-2000;
       if (wordsOver2000 <0) {wordsOver2000 = 0}
       words = words - wordsOver2000;
       var Tprice = (((price * words) + (price * 1.00 * wordsOver2000))*er).toFixed(2);
       document.getElementById("Totprice").value = Tprice;
       document.getElementById("Totprice2").innerHTML = "Your Quote Total Is: " + Tprice
    }
    </script>

  • #7
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,869
    Thanks
    79
    Thanked 4,418 Times in 4,383 Posts
    That second bit of code replaces the single line
    Code:
       var words = document.getElementById("words").value;
    in your posted code.

    I figured you can work out the math to get the right number of days, given the numberOfDays and numberOfWords (per numberOfDays).

    No?
    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.

  • #8
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,869
    Thanks
    79
    Thanked 4,418 Times in 4,383 Posts
    Oh, W.T.H. It's easy enough:
    Code:
    var info = document.getElementById("words").value.split(";");
    var numberOfDays = +info[0];
    var numberOfWords = +info[1];
    var words = +info[2]; // your original words value
    
    var wordsPerDay = numberOfWords / numberOfDays;
    var elapsedDays = Math.ceil( words / wordsPerDay ); // the number of days you report to the user
    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.

  • #9
    Senior Coder jmrker's Avatar
    Join Date
    Aug 2006
    Location
    FL
    Posts
    3,091
    Thanks
    38
    Thanked 498 Times in 492 Posts
    Quote Originally Posted by Limey10 View Post
    Hi Jmrker

    Thank you for your response.

    I don't think I explained my problem properly (sorry). I am looking for the generator to calculate the number of days that it will take to edit the client's fixed number of words when they select a particular package (which has constraints of only a certain number of words can be edited per individual package)

    ...

    As you can see, the same number of words using different packages produces different return times.

    I feel bad because you spent precious time on that code (apologies).

    Regards, Phil
    No, I don't think you were specific enough (for me), but if I understand you now and if the selections have not changed,
    would not the display of the variable "wordRange" give you the number of days you wanted to display?

    put an alert just after it is calculated or add another element to display the result.

    Modification:
    Code:
    //   var Tprice = (((price * words) + (price * 1.00 * wordsOver2000))*er).toFixed(2);
       document.getElementById("Totprice").value = Tprice;
       document.getElementById("Totprice2").innerHTML = "Your Quote Total Is: " + Tprice
       document.getElementById("Totprice2").innerHTML += "<p>Expected completion in " + wordRange + ' days';
    
    Last edited by jmrker; 07-21-2014 at 09:21 PM.

  • #10
    New Coder Limey10's Avatar
    Join Date
    Sep 2009
    Location
    Malaysia
    Posts
    61
    Thanks
    9
    Thanked 0 Times in 0 Posts
    Hi Xelawho

    Thanks for showing me the completed code. I can see how you got the wpd values. If i understand it correctly, the alert function gives me the number of days in a pop-up box. Is there anyway of making that value appear a permanent box, possibly under the total price box?

    Thanks, Phil

    Quote Originally Posted by xelawho View Post
    another approach would be to have an array that specifies the number of words per day to match the select options (kind of clunky to update, but if those numbers don't change that shouldn't be a worry). The you just divide the total words by that amount and round up to the nearest whole number. The below code uses you html as posted in #1:

    Code:
    <script type="text/javascript">
    
    function update(){
    	var exchangeRates = [1, 0.31, 0.206, 0.250];
    	var wpd=[4000,2000,1334,0,2500,1667,1000,0,2500,1000,625,0,2500,1000,715];
       var er = exchangeRates[document.getElementById("Currency").value];// selected exchange rate
       var price = document.getElementById("Package").value;
       var words = document.getElementById("words").value;
       var oneday=wpd[document.getElementById("Package").selectedIndex];
       var days=Math.ceil(words/oneday);
       alert(days+" days turnaround");
       if (words != "") {
          words = parseInt(words);
          if (isNaN (words)) {
             alert ("Please enter the number of words in figures");
             document.getElementById("words").value = "";
             return false;
          }
       }
       var wordsOver2000 = words-2000;
       if (wordsOver2000 <0) {wordsOver2000 = 0}
       words = words - wordsOver2000;
       var Tprice = (((price * words) + (price * 1.00 * wordsOver2000))*er).toFixed(2);
       document.getElementById("Totprice").value = Tprice;
       document.getElementById("Totprice2").innerHTML = "Your Quote Total Is: " + Tprice
    }
    </script>
    "I'm still smiling because they haven't found the bodies yet.....muhahaha (evil laugh)"
    GrammarProofing

  • #11
    Senior Coder xelawho's Avatar
    Join Date
    Nov 2010
    Posts
    2,980
    Thanks
    56
    Thanked 557 Times in 554 Posts
    if you mean a permanent box like the one that shows the price, it's the same routine - add a readonly input to your html, give it an ID, then once you've made your calculation, update its value using getElementById

  • Users who have thanked xelawho for this post:

    Limey10 (07-22-2014)

  • #12
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,869
    Thanks
    79
    Thanked 4,418 Times in 4,383 Posts
    That last question, and the need for Xelawho's answer, is a little scary.

    Have you not learned anything from all the coding help you have gotten? Maybe it's time to consider paying somebody to write code for you.
    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.

  • #13
    New Coder Limey10's Avatar
    Join Date
    Sep 2009
    Location
    Malaysia
    Posts
    61
    Thanks
    9
    Thanked 0 Times in 0 Posts
    Sorry if I scared you Old Pedant

    Do you remember a time when you didn't know the answer to something and you asked for help? I don't do this on a daily basis; i'm not a Supreme Master Coder like you, but I do like to try to understand - maybe I could have a little credit for that.

    I'm really not that scary :-), but thanks for your help anyway.

    Phil
    "I'm still smiling because they haven't found the bodies yet.....muhahaha (evil laugh)"
    GrammarProofing

  • #14
    New Coder Limey10's Avatar
    Join Date
    Sep 2009
    Location
    Malaysia
    Posts
    61
    Thanks
    9
    Thanked 0 Times in 0 Posts
    Thanks Xelawho

    Quote Originally Posted by xelawho View Post
    if you mean a permanent box like the one that shows the price, it's the same routine - add a readonly input to your html, give it an ID, then once you've made your calculation, update its value using getElementById

    I inserted the following into HTML:

    Code:
    Your document will take approximately   
    <input type = "text" id = "Numdays" readonly />
    days to edit
    ...which now gives me a nice little box. I played around with the getElementById, I even researched it at w3schools.com (so that I would appear less scary when I ask for further help :-). I ended up with:

    Code:
    document.getElementById("Numdays").innerHTML = days
    ...but I think this is either wrong, or I am putting it in the wrong place (because it doesn't work).

    Having said all of this, i'm actually starting to like the alert that you created. I've changed it a bit to read:

    Code:
    alert("Your work will be completed within "+days+" days\nof payment confirmation\n\nPlease select OK to see your toal price");
    So it at least gives clients a hint as to how long their work will take.

    Thanks, Phil
    "I'm still smiling because they haven't found the bodies yet.....muhahaha (evil laugh)"
    GrammarProofing

  • #15
    Senior Coder xelawho's Avatar
    Join Date
    Nov 2010
    Posts
    2,980
    Thanks
    56
    Thanked 557 Times in 554 Posts
    Quote Originally Posted by Limey10 View Post
    Code:
      
    <input type = "text" id = "Numdays" readonly />
    //...
    document.getElementById("Numdays").innerHTML = days
    the problem there is that an input box does not have innerHTML, it has a value, so
    Code:
    document.getElementById("Numdays").value = days;
    should work as expected. Alert boxes are pretty much only used for debugging these days.

  • Users who have thanked xelawho for this post:

    Limey10 (07-22-2014)


  •  
    Page 1 of 2 12 LastLast

    Tags for this Thread

    Posting Permissions

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