![]() |
Simple calculation from div contents
Hello,
Could someone help me with displaying a simple calculation from a div containing a price? It's to display reward points for each product in a shop. Example: A div with a class name of 'price' holds the price of the item. A div next to it with a class name of 'points' would display the reward points calculation. So, if an item is £20, and you get 1 point per pound spent, you would get 20 points and this would be the number shown in the 'points' div. It has to be rounded DOWN, so if the item is £19.99 they would get 19 points, not 20. Does that make sense? Even better would be if someone could also show me how to calculate how much those points are worth, which is 5p per point, so in this case it would be £1.00. Thanks in advance! |
Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> |
That is excellent, thanks!
Could you explain how it works? Also, is there a way to do the converting in to how much they're worth? |
Sorry, just noticed that you've used id's for the divs. As there will be more than one on the page it would need to be a class rather than an id.
|
Good luck with that. How many on the page? Are you talking many div prices but one points div? Need all the information. How are you planning on adding the prices? I really think you need to use id's.
|
If it can't be done then it can't be done, but it would be a nice touch so just thought I'd ask.
Basically it's an online shop, so there will be many items on each page. The code for the product output only needs to be put in once and then it'll replicate for each product in a category. I had a feeling that it wouldn't be possible for more than one box/div. I can't give a separate id or class to each area underneath the product, it has to be just one, all the same. The prices will be added automatically from the CMS. |
Anyone?
|
Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> |
Quote:
|
Thanks xelawho for the updated script using classes, that should work fine now.
Your question about the points being worth 5p - that's 5p each for when they're spending their accumulated points, so they get a point for each £1 they spend (ie. 20 points for £20 spend) and that works out as £1 (20 points x 5p each) that they can then save on a future purchase. That's basically how reward/loyalty points work. If there was a way to show that as well then it would be perfect. Sunfighter, I can't do it that way as I'm not building the shop from scratch, it's on an ecommerce platform and I don't have full control over things like that. But I appreciate your help. |
I think I might be getting it...
Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> |
Hi again,
Just bumping this as, although it was 'solved', I need a variation of the code. Basically, xelawho's code above works fine if there are no other empty divs on the page, but when there are it's placing the points total in them. So what I need is for the script to ONLY put the calculated points total in to the div with the class "points". Does that make sense? If you think of a row of products, and underneath each product image there are two boxes. One box has the price in it and has a class "price", the other box is where the worked out loyalty points go and has a class of "points". I need it to calculate the points total from the price box and display the points in the points box. Thanks in advance for all your help. It's almost there! |
Can anyone help with this? Perhaps someone who has already answered?
|
Third bump.
Is there ANYONE who can help with this, PLEEEEASE? The script's already there, up above. I just need someone to help with getting the points value to appear in a div with a class of 'points'. Please help, it's really important to me. |
Quote:
Also, where are the blank (non-point) <div>s supposed to appear? |
| All times are GMT +1. The time now is 08:22 PM. |
Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.