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 8502533
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T01:30:44+00:00 2026-06-11T01:30:44+00:00

I am currently working with radio buttons and checkboxes. In this example project I

  • 0

I am currently working with radio buttons and checkboxes. In this example project I have radio buttons and checkboxes displaying an image based on the value that is chosen by a user.

How can I add a value price to each item chosen and display total cost at the bottom? EXAMPLE

The js below shows the process in which I am displaying the images based on the value chosen.

JS

<script>
function check_value(currentElement, val, id, type) {
    var el = document.getElementById("imgBox" + id);
    if (val > 0 && val < 4) { //will trigger when [1,2,3]

        if(currentElement.checked)
        {
            el.src = "images/" + type + val + ".jpg";
            el.style.display = "";
        }
        else
        {
            el.src = "";
            el.style.display = "none";
        }           
    }
}    
</script>

HTML

<h2>Choose a bike</h2>
<form name="builder">
    <input type="radio" name="field" onclick='check_value(this, 1, 1, "bike")'/> KAWASAKI KX 450F- $8,399<br />
    <input type="radio" name="field" onclick='check_value(this, 2, 1, "bike")'/> 2010 Yamaha Road Star S- $13,090<br />
    <input type="radio" name="field" onclick='check_value(this, 3, 1, "bike")'/> Aprilia RSV4- $16,999<br />
</form>

<img id="imgBox1" src="#" style="display:none"> 

<h2>Choose a tire</h2>  
<form name="tire">
    <input type="radio" name="field" onclick='check_value(this, 1, 2, "tire")'/> Michelin Pilot Road 3 Tires- $299.99<br />
    <input type="radio" name="field" onclick='check_value(this, 2, 2, "tire")'/> Dunlop Roadsmart Sport-Touring Tires- $154.99<br />
    <input type="radio" name="field" onclick='check_value(this, 3, 2, "tire")'/> Pirelli Scorpion Trail Tires- $119.99<br />
</form>

<img id="imgBox2" src="#" style="display:none">

<h2>Choose Accesories</h2>
<form name="tire">
    <input type="checkbox" name="field" onclick='check_value(this, 1, "3a", "accessories")'/> Chrome Front Plate- $246.50<br />
    <input type="checkbox" name="field" onclick='check_value(this, 2, "3b", "accessories")'/> Jacket- $87.99<br />
    <input type="checkbox" name="field" onclick='check_value(this, 3, "3c", "accessories")'/> Gloves- $35.99            
</form>

<div id="accessories">
    <img id="imgBox3a" src="#" style="display:none">
    <img id="imgBox3b" src="#" style="display:none">
    <img id="imgBox3c" src="#" style="display:none">
</div>
  • 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-11T01:30:46+00:00Added an answer on June 11, 2026 at 1:30 am

    I would start to

    1. remove unnecessary formTags and reduce it down to one.
    2. Change input names (eg: “cylces” and “tire” for radios and “frontPlate” see code below).
    3. correct function (reduce params) and set price as value attribut of input fields
    4. add for-loop to calculate current total

    Here we are …

    <head>
        <title></title>
        <script>
            function check_value(curElem, id) {
                var el = document.getElementById("img" + curElem.name);
                el.src = "images/" + curElem.name + id + ".jpg";
                if (!curElem.checked)
                    el.style.display = "none";
                else
                    el.style.display = "block";
    
                // calculate Total
                var total = 0;
                var controls = document.getElementsByTagName('input');
                for (var i = 0; i < controls.length; i++) {
                    if ((controls[i].type === 'radio' || controls[i].type === 'checkbox') && controls[i].checked)
                        total = total + parseFloat(controls[i].value);
                }
                document.getElementById("total").innerHTML = total;
                //alert("Total: " + total);
            }    
        </script>
    </head>
    <body>
        <form name="builder">
            <h2>
                Choose a bike</h2>
            <input type="radio" name="Bike" value="8399" onclick='check_value(this, 1)' />
            KAWASAKI KX 450F- $8,399<br />
            <input type="radio" name="Bike" value="13090" onclick='check_value(this, 2)' />
            2010 Yamaha Road Star S- $13,090<br />
            <input type="radio" name="Bike" value="16999" onclick='check_value(this, 3)' />
            Aprilia RSV4- $16,999<br />
            <img id="imgBike" src="#" style="display: none" />
            <h2>
                Choose a tire</h2>
            <input type="radio" name="Tire" value="299.99" onclick='check_value(this, 1)' />
            Michelin Pilot Road 3 Tires- $299.99<br />
            <input type="radio" name="Tire" value="154.99" onclick='check_value(this, 2)' />
            Dunlop Roadsmart Sport-Touring Tires- $154.99<br />
            <input type="radio" name="Tire" value="119.99" onclick='check_value(this, 3)' />
            Pirelli Scorpion Trail Tires- $119.99<br />
            <img id="imgTire" src="#" style="display: none" />
            <h2>
                Choose Accesories</h2>
            <input type="checkbox" name="FrontPlate" value="246.50" onclick='check_value(this, "")' />
            Chrome Front Plate- $246.50<br />
            <input type="checkbox" name="Jacket" value="87.90" onclick='check_value(this, "")' />
            Jacket- $87.99<br />
            <input type="checkbox" name="Gloves"  value="35.99" onclick='check_value(this, "")' />
            Gloves- $35.99
            <div id="accessories">
                <img id="imgFrontPlate" src="#" style="display: none" />
                <img id="imgJacket" src="#" style="display: none" />
                <img id="imgGloves" src="#" style="display: none" />
            </div>
            <div id="total"></div>
        </form>
    </body>
    

    Although this might be a solution to your answer – I don’t see the use of this code. In a real life environment most of the data will come from a server generated so you will have to completely re-do this code!

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

Sidebar

Related Questions

I am currently working with displaying images based on the value chosen from a
I am currently working with radio buttons and check boxes to display images based
I am currently working with radio buttons to display an image when clicked on
Currently working on a flex AIR project based on PureMVC framework. There was a
Hi I have an array that stores when radio buttons are checked so that
I am currently working with radio buttons and check boxes to display images with
I am currently working on a project that involves creating a questionnaire from a
Using Javascript and html: I have a list containing radio buttons that is dynamically
Currently working with converting SQLException error messages into messages that are more useful for
Currently working in the deployment of an OFBiz based ERP, we've come to the

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.