Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8115821
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T03:35:22+00:00 2026-06-06T03:35:22+00:00

I need to create a piece of script that looks through a variety of

  • 0

I need to create a piece of script that looks through a variety of products on a page, works out the percentage off using the ‘was’ and ‘now’ prices and then display an image for that product that represents the percentage off.

So far I can loop through all the products and run the percentage script to display an image but the same image is shown on all products instead of different images for different percentages. Does anyone know how I can make the percentage script run for each product and not duplicate?

Here’s some dummy HTML:

<div id="prods">
<div id="discountWasPrice" style="display:none;">50</div>
<div id="discountSellPrice" style="display:none;">25</div>
<div id="discount50"></div>
</div>

<div id="prods">
<div id="discountWasPrice" style="display:none;">75</div>
<div id="discountSellPrice" style="display:none;">25</div>
<div id="discount50"></div>
</div>

<div id="prods">
<div id="discountWasPrice" style="display:none;">10</div>
<div id="discountSellPrice" style="display:none;">8</div>
<div id="discount50"></div>
</div>

And here’s the javascript so far:

<script type="text/javascript">
var discount = $("div#discount50");
var prods = $("div#prods");
var discountLen = $("div#prods").length;
for(var i = 0; i < discountLen; i++){
var x = $('#discountWasPrice').text();
var f = $('#discountSellPrice').text();
var g = 1-(f/x);
percent= (g * 100).toFixed(2);
if ((percent > 4.00) && (percent < 10.00)) {
    discount[i].innerHTML+="<a href=\"\"><img src=\"5percent.png\"></a>";}
if ((percent > 9.00) && (percent < 15.00)) {
discount[i].innerHTML+="<a href=\"\"><img src=\"10percent.png\"></a>";}
if ((percent > 14.00) && (percent < 20.00)) {
discount[i].innerHTML+="<a href=\"\"><img src=\"15percent.png\"></a>";}
if ((percent > 19.00) && (percent < 25.00)) {
discount[i].innerHTML+="<a href=\"\"><img src=\"20percent.png\"></a>";}
if ((percent > 24.00) && (percent < 30.00)) {
discount[i].innerHTML+="<a href=\"\"><img src=\"25percent.png\"></a>";}
if ((percent > 29.00) && (percent < 35.00)) {
discount[i].innerHTML+="<a href=\"\"><img src=\"30percent.png\"></a>";}
if ((percent > 34.00) && (percent < 40.00)) {
discount[i].innerHTML+="<a href=\"\"><img src=\"35percent.png\"></a>";}
if ((percent > 39.00) && (percent < 45.00)) {
discount[i].innerHTML+="<a href=\"\"><img src=\"40percent.png\"></a>";}
if ((percent > 44.00) && (percent < 50.00)) {
discount[i].innerHTML+="<a href=\"\"><img src=\"45percent.png\"></a>";}
if ((percent > 49.00) && (percent < 60.00)) {
discount[i].innerHTML+="<a href=\"\"><img src=\"50percent.png\"></a>";}
if ((percent > 59.00) && (percent < 70.00)) {
discount[i].innerHTML+="<a href=\"\"><img src=\"60percent.png\"></a>";}
if ((percent > 69.00) && (percent < 75.00)) {
discount[i].innerHTML+="<a href=\"\"><img src=\"70percent.png\"></a>";}
if (percent > 74.00) {
discount[i].innerHTML+="<a href=\"\"><img src=\"70percentplus.png\"></a>";}
}
</script>

Any help is much appreciated,

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T03:35:23+00:00Added an answer on June 6, 2026 at 3:35 am

    Move your “id” to “class” for every div, then get some jquery magic to loop on all your divs…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hi I need to create a service that runs a piece of code in
Need to create a custom DNS name server using C which will check against
I have a piece of code that essentially looks like this: <div class=parent> <a
I have a working perl script that grabs the data I need and displays
I started to create a script that allows me to split a big image
I need to create a Windows service that checks when a user logs in
I'm trying to create a piece of shared memory that holds an array of
So imagine a piece of Javascript as the first script on a page along
I have a python modules question: I need to write a script that will
I need to create an XML document from a piece of plain text and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.