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 9 of 9
  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 - re-visited

    Hi all again,

    Firstly thanks to Philip M for getting me this far but i still have a few quirks that i'd like to get around.

    Its a price generator with 3 options. User selects an option from a drop down, inputs "number of words" and hey-presto the price appears.

    That works superbly well but what would be really cool is if after someone gets a price they then would like to select a different option in order to see a new price. At the moment it means selecting another option and re-entering the number of words and then clicking in the price box to get the new result.

    Is there anyway to make that price change automatically (as if by magic even) if either the "option" or "number of words" is changed

    I have a sneaky suspicion that Philip M will come to the rescue again but should anyone else have a view that would be great also.

    Thanks as always in advance, Phil

    Code:
    <head>
    <!--quote generator -->
    <script type="text/javascript">
    function update(){
    var price = document.getElementById("Package").value;
    var words = document.getElementById("words").value;
    var wordsOver2000 = words-2000;
    if (wordsOver2000 <0) {wordsOver2000 = 0}
    words = words - wordsOver2000;
    var Tprice = ((price * words) + (price * .80 * wordsOver2000)).toFixed(2) ;document.getElementById("Totprice").value = Tprice;
    document.getElementById("Totprice2").innerHTML = "Your Quote Total Is: MYR" + Tprice
    }
    </script>
    <!--end quote generator -->
    </head>
    Code:
    <body>
    <!--quote generator -->
    <div align="center" class="generator">
      PACKAGE - <select name="Package" id = "Package">
        <option value="0.027">Economy</option>
        <option value="0.038">Standard</option>
        <option value="0.049">Express</option>
      </select>
      No. of Words -  
      <input type="text" id="words" onchange="update()" value="" />
      ---&gt; MYR 
      <input type = "text" id = "Totprice" value="...then click here" /><br />
    <br /><strong>(NB - To see a quote for a different package, please select package and re-enter the number of words)</strong>
    </div>
    <!--end quote generator -->
    </body>

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,013
    Thanks
    203
    Thanked 2,538 Times in 2,516 Posts
    Well, that's pretty easy!

    Code:
    PACKAGE - <select name="Package" id = "Package" onchange = "update()" >
    You already have

    Code:
    <input type="text" id="words" onchange="update()" value="" />
    You do not have anything to validate the number of words. You need:-

    Code:
    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;
    }
    }
    The ...then click here is pointless as entering a value for words will automatically generate the quote.

    Code:
    <input type = "text" id = "Totprice" readonly /><br />
    "In the beginner's mind there are many possibilities, but in the expert's mind there are few” - Shunryu Suzuki (Japanese Zen priest, ?-1971)
    Last edited by Philip M; 11-14-2009 at 08:10 AM.

  • Users who have thanked Philip M for this post:

    Limey10 (11-14-2009)

  • #3
    New to the CF scene
    Join Date
    Dec 2011
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts

    I ran into a problem.

    I am working on a quote calculator for a client, and I had it working, then for some reason it stopped working. I don't know if I accidentally changed the code or what. Perhaps somebody could help me find what went wrong here.

    Here is my code...

    Code:
    <!-- Quote Generator -->
    
    	<script type="text/javascript">
    
    	function update1()
    {
    	var leads = document.getElementById("Leads").value;
    	var cost = (leads * 142.2).toFixed(0) ; document.getElementById("Cost").value = cost;
    	var perlead = (cost / leads).toFixed(0) ; document.getElementById("PerLead").value = perlead;
    	var hours = (leads * 4.06).toFixed(0) ; document.getElementById("Hours").value = hours;
    }
    	function update2()
    {
    	var leads = document.getElementById("Leads").value;
    	var cost = document.getElementById("Cost").value;
    	var revenue = document.getElementById("Revenue").value;
    	var trev = ((leads * .30) * revenue).toFixed(0) ; document.getElementById("Trev").value = trev;
    	var roi = (((trev - cost) / cost) * 100)).toFixed(0) ; document.getElementById("ROI").value = roi;
    }
    
    	</script>
    
    <!-- Quote Generator -->
    Code:
    <!-- Quote Generator -->
    
    	<div align="center" class"quote">
    	<table id="quote" width="500">
    	<tr align="right">
    		<td>
    			How Many Qualified Leads Do You Want
    		</td>
    		<td width="150">
    			<input type="text" size="10" id="Leads" onChange="update1()" value="" />
    		</td>
    	</tr>
    	<tr align="right">
    		<td>
    			Total Campaign Cost
    		</td>
    		<td>
    			$<input type="text" size="10" id="Cost" readonly />
    		</td>
    	</tr>
    	<tr align="right">
    		<td>
    			Cost / Lead - Average
    		</td>
    		<td>
    			$<input type="text" size="10" id="PerLead" readonly />
    		</td>
    	</tr>
    	<tr align="right">
    		<td>
    			Total Hours Diverted to Sales Appts vs Lead Gen
    		</td>
    		<td>
    			<input type="text" size="10" id="Hours" readonly />
    		</td>
    	</tr>
    	<tr align="right">
    		<td>
    			Your Revenue / Close
    		</td>
    		<td width="150">
    			$<input type="text" size="10" id="Revenue" onChange="update2()" value="" />
    		</td>
    	</tr>
    	<tr align="right">
    		<td>
    			Total Revenue
    		</td>
    		<td>
    			$<input type="text" size="10" id="Trev" readonly />
    		</td>
    	</tr>
    	<tr align="right">
    		<td>
    			ROI
    		</td>
    		<td>
    			%<input type="text" size="10" id="ROI" readonly />
    		</td>
    	</tr>
    	</table>
    	</div>
    
    <!-- Quote Generator -->

  • #4
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,013
    Thanks
    203
    Thanked 2,538 Times in 2,516 Posts
    Have you tried using your error console or Firebug?

    .toFixed() changes the number to a string value, which cannot then be used for any further arithmetic calculations. So to.Fixed() should only be used to format numbers for display.

    And it is quite wrong to convert a value to an integer with .toFixed(0). Use parseInt() or Math.round() instead.

    Code:
    var cost = (leads * 142.2); 
    document.getElementById("Cost").value = parseInt(cost);
    And do not place multiple statements on the same line. You mention a client - surely you are not proposing to charge someone for this stuff?

    Quizmaster: Tallinn is the capital of which Baltic state?
    Contestant: Spain.
    Last edited by Philip M; 12-04-2011 at 11:59 AM. Reason: Typo

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

  • #5
    New to the CF scene
    Join Date
    Dec 2011
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Why do you say that?

    Plus sadly, your suggestion did not work.
    Last edited by Everlight; 12-04-2011 at 04:02 PM. Reason: Additional input.

  • #6
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,013
    Thanks
    203
    Thanked 2,538 Times in 2,516 Posts
    Quote Originally Posted by Everlight View Post
    Why do you say that?

    Plus sadly, your suggestion did not work.
    Say what?

    There are undoubtedly other errors in your code. Hint - look for unmatched brackets. And use your error console.
    Last edited by Philip M; 12-04-2011 at 04:32 PM.

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

  • #7
    New to the CF scene
    Join Date
    Dec 2011
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Wish i had an error console.

  • #8
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,013
    Thanks
    203
    Thanked 2,538 Times in 2,516 Posts
    Quote Originally Posted by Everlight View Post
    Wish i had an error console.
    Every modern browser includes an error console. In Internet Explorer press F12.
    In Chrome navigate to Developer Tools.
    Use Firebug with Firefox.

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

  • Users who have thanked Philip M for this post:

    Everlight (12-04-2011)

  • #9
    New to the CF scene
    Join Date
    Dec 2011
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Ah gotchya, Thank you for the tip.


  •  

    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
    •