Connecting Tech Pros Worldwide Forums | Help | Site Map

Help With Javascript

Newbie
 
Join Date: Feb 2007
Posts: 5
#1: Feb 24 '07
Hi,

First let me say I do not know java much at all. Anyway, on my new website I have products that I want to have tiered pricing for. (i.e. 1-5 price $17.85, 6-11 price is $14.85, 12-23 price is $13.85, 24+ price is $11.85.) I want to offer tiered pricing but not sure how to do this. Any help or pointing me in the right direction would greatly be appreciated.

Thanks,
Berri
Lives Here
 
Join Date: Sep 2006
Posts: 12,070
#2: Feb 24 '07

re: Help With Javascript


Quote:

Originally Posted by decorator

Hi,

First let me say I do not know java much at all. Anyway, on my new website I have products that I want to have tiered pricing for. (i.e. 1-5 price $17.85, 6-11 price is $14.85, 12-23 price is $13.85, 24+ price is $11.85.) I want to offer tiered pricing but not sure how to do this. Any help or pointing me in the right direction would greatly be appreciated.

Thanks,
Berri

Are you sure you want to use Java or did you mean Javascript? You will have to suppy more info and show the codes you have and where you want to put these prices.
Newbie
 
Join Date: Feb 2007
Posts: 5
#3: Feb 24 '07

re: Help With Javascript


Quote:

Originally Posted by r035198x

Are you sure you want to use Java or did you mean Javascript? You will have to suppy more info and show the codes you have and where you want to put these prices.

Yes, sorry, I want a javascript to allow for multi level prices. If a customer orders 4 sets it is one price if its > 6 another price etc.

Ok, I do not know javascript but I can learn it, I think.

As an example I will have lots of products with different price variations but here is one, http://www.yourgiftspersonalized.com/Sailboat-Tealight-Holders-Set-of-4-p-76.html

Now here is what I think I need to add:

<script language=”javascript”>
Var data = {
<product productid=”76”>
<quantity> <6 </quantity>
<price>17.85</price>
<quantity> <12 </quantity>
<price> 14.85</price>
<quanity> <24 </quantity>
<price> 13.85</price>
<quantity> =>24</quantity>
<price>11.85</price>
</product>
};
</script>

My coding is probably incorrect but hopefully someone will understand.
The pricing for this particular product is: 1-5 = 17.85; 6-11= 14.85; 12-23= 13.85; 24+ = 11.85. I don't know how to do the if quantity is greater than or equal to so any help with this would be appreciated. I just did if greater than.

With xcart there is a place for me to add price modifiers and input javascript for each product I enter but since I don't know javascript I was hoping for help understanding if I am way off or on the right track or just plain help.

Another question with the code I have, do I need to find the productid # for each product or is there a better way to do that?

Thanks for your help!
Berri
Familiar Sight
 
Join Date: Dec 2006
Posts: 157
#4: Feb 24 '07

re: Help With Javascript


Quote:

Originally Posted by decorator

Yes, sorry, I want a javascript to allow for multi level prices. If a customer orders 4 sets it is one price if its > 6 another price etc.

Ok, I do not know javascript but I can learn it, I think.

As an example I will have lots of products with different price variations but here is one, http://www.yourgiftspersonalized.com...of-4-p-76.html

Now here is what I think I need to add:

<script language=”javascript”>
Var data = {
<product productid=”76”>
<quantity> <6 </quantity>
<price>17.85</price>
<quantity> <12 </quantity>
<price> 14.85</price>
<quanity> <24 </quantity>
<price> 13.85</price>
<quantity> =>24</quantity>
<price>11.85</price>
</product>
};
</script>

My coding is probably incorrect but hopefully someone will understand.
The pricing for this particular product is: 1-5 = 17.85; 6-11= 14.85; 12-23= 13.85; 24+ = 11.85. I don't know how to do the if quantity is greater than or equal to so any help with this would be appreciated. I just did if greater than.

With xcart there is a place for me to add price modifiers and input javascript for each product I enter but since I don't know javascript I was hoping for help understanding if I am way off or on the right track or just plain help.

Another question with the code I have, do I need to find the productid # for each product or is there a better way to do that?

Thanks for your help!
Berri

Hello Berri,
Java and JavaScript are not the same.This is the Java forum pal, you need to post in the JavaScript forum.They'll be able to help you out with the appropriate suggestions.

By the way here's a good link to start learning JavaScript if you are looking to code in it.
Newbie
 
Join Date: Feb 2007
Posts: 5
#5: Feb 24 '07

re: Help With Javascript


Hi,

First let me say I do not know java much at all. Anyway, on my new website I have products that I want to have tiered pricing for. (i.e. 1-5 price $17.85, 6-11 price is $14.85, 12-23 price is $13.85, 24+ price is $11.85.) I want to offer tiered pricing but not sure how to do this. Any help or pointing me in the right direction would greatly be appreciated.

I want a javascript to allow for multi level prices. If a customer orders 4 sets it is one price if its > 6 another price etc.

Ok, I do not know javascript but I can learn it, I think.

As an example I will have lots of products with different price variations but here is one, http://www.yourgiftspersonalized.com/Sailboat-Tealight-Holders-Set-of-4-p-76.html

Now here is what I think I need to add:

<script language=”javascript”>
Var data = {
<product productid=”76”>
<quantity> <6 </quantity>
<price>17.85</price>
<quantity> =6<12 </quantity>
<price> 14.85</price>
<quanity> =12<24 </quantity>
<price> 13.85</price>
<quantity> =>24</quantity>
<price>11.85</price>
</product>
};
</script>

My coding is probably incorrect but hopefully someone will understand.
The pricing for this particular product is: 1-5 = 17.85; 6-11= 14.85; 12-23= 13.85; 24+ = 11.85. I don't know how to do the if quantity is greater than or equal to so any help with this would be appreciated. I just did if greater than.

With xcart there is a place for me to add price modifiers and input javascript for each product I enter but since I don't know javascript I was hoping for help understanding if I am way off or on the right track or just plain help.

Another question with the code I have, do I need to find the productid # for each product or is there a better way to do that?

Thanks,
Berri
Newbie
 
Join Date: Feb 2007
Location: Alabama, USA
Posts: 19
#6: Feb 25 '07

re: Help With Javascript


I'm not sure but it looks like X-Cart provides that feature without needing Javascript.

Search for "price modifier" in the X-Cart Manual.

Btw...

On your page, in every place where you have this:

onclick="javascript: js_code...

you need to remove "javascript:".

:)
Newbie
 
Join Date: Feb 2007
Posts: 5
#7: Feb 25 '07

re: Help With Javascript


Quote:

Originally Posted by MikeFoster

I'm not sure but it looks like X-Cart provides that feature without needing Javascript.

Search for "price modifier" in the X-Cart Manual.

Btw...

On your page, in every place where you have this:

onclick="javascript: js_code...

you need to remove "javascript:".

:)

Hi Mike,

Yes, X-Cart does have the price modifier, the problem with that is I have to list each number 1-100 and for 1-5 leave blank since the default price is already in place with the product. So when I set up the product modifier it would say tiered price 1, 2, 3, 4, 5, 6, etc and than the qty box is there and it is really confusing. I was trying to add a javascript code to so when a customer put in "14" in the qty. box it would calculate the cost at the 13.85 price. 13.85 x 14. The way X-Cart has it with the price modifier is really confusing.

I was hoping to put in a java code that would do that but I don't know the correct java code.

Berri
Newbie
 
Join Date: Feb 2007
Location: Alabama, USA
Posts: 19
#8: Feb 25 '07

re: Help With Javascript


I don't know anything about X-Cart - I only just peeked at the manual.

Here is some basic Javascript - this is only for you to have an idea of what the script might look like. It is not intended to be a final solution.

First, add the following onchange handler to the select:

Expand|Select|Wrap|Line Numbers
  1. <select id="product_avail" name="amount" onchange='adjustPrice(this)'>
  2.  
Now put this in one of the script elements (preferably in the head):
Expand|Select|Wrap|Line Numbers
  1. function adjustPrice(sel)
  2. {
  3.   var p = '', q = parseInt(sel.options[sel.selectedIndex].value);
  4.   if (!q) {
  5.     alert('Error!');
  6.     return;
  7.   }
  8.   else if (q >= 24) {
  9.     p = '11.85';
  10.   }
  11.   else if (q >= 12) {
  12.     p = '13.85';
  13.   }
  14.   else if (q >= 6) {
  15.     p = '14.85';
  16.   }
  17.   else {
  18.     p = '17.85';
  19.   }
  20.   document.getElementById('product_price').innerHTML = '$' + p;
  21. }
  22.  
This updates the price on the page (but not actually in the right place) - but it does not put it in the form to be submitted.

Where does the original price come from? Is it in a database on the server? If so then can you change the server-side code to output Js into the html file? I'm assuming you don't want to hard-code these prices in each page.

I could go on but...

as you can see, the Javascript is the easiest part of this task - the real changes should be made in the server-side script. Using Javascript to select a price should only be used for convenience. Your server-side code must still validate the users choices.
Newbie
 
Join Date: Feb 2007
Posts: 5
#9: Feb 25 '07

re: Help With Javascript


Quote:

Originally Posted by MikeFoster

I don't know anything about X-Cart - I only just peeked at the manual.

Here is some basic Javascript - this is only for you to have an idea of what the script might look like. It is not intended to be a final solution.

First, add the following onchange handler to the select:

Expand|Select|Wrap|Line Numbers
  1. <select id="product_avail" name="amount" onchange='adjustPrice(this)'>
  2.  
Now put this in one of the script elements (preferably in the head):
Expand|Select|Wrap|Line Numbers
  1. function adjustPrice(sel)
  2. {
  3.   var p = '', q = parseInt(sel.options[sel.selectedIndex].value);
  4.   if (!q) {
  5.     alert('Error!');
  6.     return;
  7.   }
  8.   else if (q >= 24) {
  9.     p = '11.85';
  10.   }
  11.   else if (q >= 12) {
  12.     p = '13.85';
  13.   }
  14.   else if (q >= 6) {
  15.     p = '14.85';
  16.   }
  17.   else {
  18.     p = '17.85';
  19.   }
  20.   document.getElementById('product_price').innerHTML = '$' + p;
  21. }
  22.  
This updates the price on the page (but not actually in the right place) - but it does not put it in the form to be submitted.

Where does the original price come from? Is it in a database on the server? If so then can you change the server-side code to output Js into the html file? I'm assuming you don't want to hard-code these prices in each page.

I could go on but...

as you can see, the Javascript is the easiest part of this task - the real changes should be made in the server-side script. Using Javascript to select a price should only be used for convenience. Your server-side code must still validate the users choices.

Mike,

Thanks!

This site uses X-Cart which I am not familiar with and am trying to learn, I know for each product I can add a customer side but will have to look at the server-side. Yeah, I do not want to hard code this on all pages, some products will have tiered prices that will all have different price points so I am trying to find the best way to do this and make it easy for the customers at the same time.

Where in AL?

Berri
Newbie
 
Join Date: Feb 2007
Location: Alabama, USA
Posts: 19
#10: Feb 25 '07

re: Help With Javascript


North Etowah county :)
Lives Here
 
Join Date: Sep 2006
Posts: 12,070
#11: Feb 26 '07

re: Help With Javascript


Quote:

Originally Posted by decorator

Yes, sorry, I want a javascript to allow for multi level prices. If a customer orders 4 sets it is one price if its > 6 another price etc.

Ok, I do not know javascript but I can learn it, I think.

As an example I will have lots of products with different price variations but here is one, http://www.yourgiftspersonalized.com/Sailboat-Tealight-Holders-Set-of-4-p-76.html

Now here is what I think I need to add:

<script language=”javascript”>
Var data = {
<product productid=”76”>
<quantity> <6 </quantity>
<price>17.85</price>
<quantity> <12 </quantity>
<price> 14.85</price>
<quanity> <24 </quantity>
<price> 13.85</price>
<quantity> =>24</quantity>
<price>11.85</price>
</product>
};
</script>

My coding is probably incorrect but hopefully someone will understand.
The pricing for this particular product is: 1-5 = 17.85; 6-11= 14.85; 12-23= 13.85; 24+ = 11.85. I don't know how to do the if quantity is greater than or equal to so any help with this would be appreciated. I just did if greater than.

With xcart there is a place for me to add price modifiers and input javascript for each product I enter but since I don't know javascript I was hoping for help understanding if I am way off or on the right track or just plain help.

Another question with the code I have, do I need to find the productid # for each product or is there a better way to do that?

Thanks for your help!
Berri

Moved to Javascript forum.
acoder's Avatar
Site Moderator
 
Join Date: Nov 2006
Location: UK
Posts: 14,581
#12: Feb 27 '07

re: Help With Javascript


Threads merged.
Reply