Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 11-14-2009, 07:42 AM   PM User | #1
Limey10
New Coder

 
Join Date: Sep 2009
Location: Malaysia
Posts: 43
Thanks: 6
Thanked 0 Times in 0 Posts
Limey10 is an unknown quantity at this point
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>
Limey10 is offline   Reply With Quote
Old 11-14-2009, 07:53 AM   PM User | #2
Philip M
Supreme Master coder!

 
Philip M's Avatar
 
Join Date: Jun 2002
Location: London, England
Posts: 17,033
Thanks: 197
Thanked 2,410 Times in 2,388 Posts
Philip M has a spectacular aura aboutPhilip M has a spectacular aura aboutPhilip M has a spectacular aura about
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..
Philip M is online now   Reply With Quote
Users who have thanked Philip M for this post:
Limey10 (11-14-2009)
Old 12-04-2011, 11:39 AM   PM User | #3
Everlight
New to the CF scene

 
Join Date: Dec 2011
Posts: 4
Thanks: 1
Thanked 0 Times in 0 Posts
Everlight is an unknown quantity at this point
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 -->
Everlight is offline   Reply With Quote
Old 12-04-2011, 11:52 AM   PM User | #4
Philip M
Supreme Master coder!

 
Philip M's Avatar
 
Join Date: Jun 2002
Location: London, England
Posts: 17,033
Thanks: 197
Thanked 2,410 Times in 2,388 Posts
Philip M has a spectacular aura aboutPhilip M has a spectacular aura aboutPhilip M has a spectacular aura about
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.
__________________

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.

Last edited by Philip M; 12-04-2011 at 11:59 AM.. Reason: Typo
Philip M is online now   Reply With Quote
Old 12-04-2011, 03:55 PM   PM User | #5
Everlight
New to the CF scene

 
Join Date: Dec 2011
Posts: 4
Thanks: 1
Thanked 0 Times in 0 Posts
Everlight is an unknown quantity at this point
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.
Everlight is offline   Reply With Quote
Old 12-04-2011, 04:22 PM   PM User | #6
Philip M
Supreme Master coder!

 
Philip M's Avatar
 
Join Date: Jun 2002
Location: London, England
Posts: 17,033
Thanks: 197
Thanked 2,410 Times in 2,388 Posts
Philip M has a spectacular aura aboutPhilip M has a spectacular aura aboutPhilip M has a spectacular aura about
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.
__________________

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.

Last edited by Philip M; 12-04-2011 at 04:32 PM..
Philip M is online now   Reply With Quote
Old 12-04-2011, 08:00 PM   PM User | #7
Everlight
New to the CF scene

 
Join Date: Dec 2011
Posts: 4
Thanks: 1
Thanked 0 Times in 0 Posts
Everlight is an unknown quantity at this point
Wish i had an error console.
Everlight is offline   Reply With Quote
Old 12-04-2011, 08:45 PM   PM User | #8
Philip M
Supreme Master coder!

 
Philip M's Avatar
 
Join Date: Jun 2002
Location: London, England
Posts: 17,033
Thanks: 197
Thanked 2,410 Times in 2,388 Posts
Philip M has a spectacular aura aboutPhilip M has a spectacular aura aboutPhilip M has a spectacular aura about
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.
Philip M is online now   Reply With Quote
Users who have thanked Philip M for this post:
Everlight (12-04-2011)
Old 12-04-2011, 08:54 PM   PM User | #9
Everlight
New to the CF scene

 
Join Date: Dec 2011
Posts: 4
Thanks: 1
Thanked 0 Times in 0 Posts
Everlight is an unknown quantity at this point
Ah gotchya, Thank you for the tip.
Everlight is offline   Reply With Quote
Reply

Bookmarks

Tags
generator, price, quotation

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 03:53 PM.


Advertisement
Log in to turn off these ads.