...

View Full Version : Issue with JS...first post and I appreciate any help



brmacdon
01-23-2012, 04:59 PM
I have created a quick little pricing engine to price some of the products that we sell. I was able to use a nice template online and it worked for most of what we offer. However, I needed to add a few filters and while doing so, needed to tweak the JS even further than I was originally comfortable with doing.

Long story short, here is the main pricing page - www.pricemyleads.com - and this is the page in question as of now - www.pricemyleads.com/taxaged.html

The js file for this page is - www.pricemyleads.com/js/taxagedformcalculations.js

Any help is greatly appreciated. You'll see the issue when you start clicking on the check boxes.

Thanks,

brmacdon

cuzMazn
01-23-2012, 05:55 PM
Hi there,

This is the first few thing I think you should change before I can go any further. Please try to replace:



var selectedFilling = theForm.elements["filling"];


By:



var selectedFilling = document.getElementById("filling");


And please do the same with the rest if you have any similar code. The problem may be there, try to insert alert() after that line to see if it returns the value you expected.

Regards,

Tim._

brmacdon
01-23-2012, 06:50 PM
Hi there,

This is the first few thing I think you should change before I can go any further. Please try to replace:



var selectedFilling = theForm.elements["filling"];


By:



var selectedFilling = document.getElementById("filling");


And please do the same with the rest if you have any similar code. The problem may be there, try to insert alert() after that line to see if it returns the value you expected.

Regards,

Tim._
That did not fix it, but I just noticed something. If you choose a quantity and then precede to check every filter it then will display the cost correctly without any of this - "Total Price For Each Lead $0.2[object HTMLInputElement]0.81[object HTMLInputElement]0.030.060.09"

Old Pedant
01-23-2012, 08:12 PM
cuzMazn gave bad advice.

If you have a <form> element that has only a name (no ID), then using getElementById() is of course utterly useless.

There are so many things wrong with that code that I would just start over.

Just for starters, look here:


var aged30=0;
//Get a refernce to the form id="cakeform"
var theForm = document.forms["cakeform"];
//Get a reference to the checkbox id="includeinscription"
var aged30 = theForm.elements["aged30"];
//If they checked the box set inscriptionPrice to 20
if(aged30.checked==true){
aged30=.00;
}
//finally we return the inscriptionPrice
return aged30;

You are using the SAME VARIABLE to refer to the element as you are using to get the value.

So if the box is *NOT* checked, you are returning a reference to the checkbox *INSTEAD* of a number.

And you haven't provide a lookup value for "None", so any unchecked box is returning a value of undefined.

And and...

I really would start over, were I you.

It's ugly to use a piece of code designed for something different. The comments in the code make no sense and you aren't covering all the cases.

brmacdon
01-23-2012, 08:39 PM
cuzMazn gave bad advice.

If you have a <form> element that has only a name (no ID), then using getElementById() is of course utterly useless.

There are so many things wrong with that code that I would just start over.

Just for starters, look here:


var aged30=0;
//Get a refernce to the form id="cakeform"
var theForm = document.forms["cakeform"];
//Get a reference to the checkbox id="includeinscription"
var aged30 = theForm.elements["aged30"];
//If they checked the box set inscriptionPrice to 20
if(aged30.checked==true){
aged30=.00;
}
//finally we return the inscriptionPrice
return aged30;

You are using the SAME VARIABLE to refer to the element as you are using to get the value.

So if the box is *NOT* checked, you are returning a reference to the checkbox *INSTEAD* of a number.

And you haven't provide a lookup value for "None", so any unchecked box is returning a value of undefined.

And and...

I really would start over, were I you.

It's ugly to use a piece of code designed for something different. The comments in the code make no sense and you aren't covering all the cases.
Just by changing the items in red, its fixed!! I dont know JS all that well and am basically just trying to patch something together! Thank you soooo much!!!!

brmacdon
01-23-2012, 08:44 PM
One last question...how do I assign a negative number to a var?

Philip M
01-23-2012, 08:50 PM
One last question...how do I assign a negative number to a var?

Is it not obvious?

var mynumber = -12;

brmacdon
01-23-2012, 08:53 PM
Is it not obvious?

var mynumber = -12;
Ha, I swear I tried the common sense answer, uploaded the file and it didn't work. Now, of course, it works fine:D THANKS!!

brmacdon
01-23-2012, 08:58 PM
Coming together and I thank everyone that has helped!

With just about every filter, it kicks back something like this (which is what I want):

"Total Price For Each Record $0.23"

But, for only a few, it shows too many decimal places:

"Total Price For Each Record $0.21000000000000002"

Any ideas?

cuzMazn
01-23-2012, 09:00 PM
cuzMazn gave bad advice.

If you have a <form> element that has only a name (no ID), then using getElementById() is of course utterly useless.

...


Hi,

Sorry about that, I didn't read the code completely and I was mistaken the name for the ID.

Tim._

Old Pedant
01-24-2012, 01:07 AM
With just about every filter, it kicks back something like this (which is what I want):

"Total Price For Each Record $0.23"

Just use total.toFixed(2)

That is, something like



var message = "Total Price for Each Record $" + total.toFixed(2);

Adjust that to use your own actual variable names, of course.

brmacdon
01-24-2012, 03:14 PM
Just use total.toFixed(2)

That is, something like



var message = "Total Price for Each Record $" + total.toFixed(2);

Adjust that to use your own actual variable names, of course.
Worked!! Thank you very much. This site is done and deployed! You may close this page if you'd like, mods!



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum