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

The Archive Base Latest Questions

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

I am currently working with displaying images based on the value chosen from a

  • 0

I am currently working with displaying images based on the value chosen from a radio button. But I am currently running into a wall with making the code as short and efficient as possible. I have several categories to choose from and they way i am approaching the issue will require for me to write several check_value#. Is there a way to combine those two functions? so in the future if i have 5 or 7 categories i wont have to have a function for each. EXAMPLE

<script>
 function check_value(val) {     
    var el = document.getElementById("imgBox1");
    var img = imgs[val];
    if (val>0 && val<4) { //will trigger when [1,2,3]
        el.src = "images/bike" + val + ".jpg";
        el.style.display = "";
    }    
}

 function check_value1(val) {    
    var el = document.getElementById("imgBox2");
    var img = imgs[val];
    if (val>0 && val<4) { //will trigger when [1,2,3]
        el.src = "images/tire" + val + ".jpg";
        el.style.display = "";
    }    
}
</script>    

HTML

<h2>Choose a bike</h2>
    <form name="builder">
        <input type="radio" name="field" value="1" onclick='check_value(0)'/> KAWASAKI KX 450F<br />
         <input type="radio" name="field" value="2" onclick='check_value(1)'/> 2010 Yamaha Road Star S<br />
         <input type="radio" name="field" value="3" onclick='check_value(2)'/> Aprilia RSV4<br />
    </form>

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

<h2>Choose a tire</h2>  
    <form name="tire">
        <input type="radio" name="field" value="1" onclick='check_value1(0)'/> Michelin Pilot Road 3 Tires<br />
        <input type="radio" name="field" value="2" onclick='check_value1(1)'/> Dunlop Roadsmart Sport-Touring Tires<br />
         <input type="radio" name="field" value="3" onclick='check_value1(2)'/> Pirelli Scorpion Trail Tires<br />
    </form>

<img id="imgBox2" src="#" style="display:none"> 
  • 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:51:58+00:00Added an answer on June 11, 2026 at 1:51 am

    try this, updated

    make image name as bike#.jpg , tire#.jpg
    bike0.jpg, bike1.jpg, bike2.jpg….

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

    }

    <h2>Choose a bike</h2>
    <form name="builder">
        <input type="radio" name="field" value="1" onclick='check_value(0, 1, "bike")'/> KAWASAKI KX 450F<br />
         <input type="radio" name="field" value="2" onclick='check_value(1, 1, "bike")'/> 2010 Yamaha Road Star S<br />
         <input type="radio" name="field" value="3" onclick='check_value(2, 1, "bike")'/> Aprilia RSV4<br />
    </form>
    
    <img id="imgBox1" src="#" style="display:none"> 
    
    <h2>Choose a tire</h2>  
    <form name="tire">
        <input type="radio" name="field" value="1" onclick='check_value(0, 2, "tire")'/> Michelin Pilot Road 3 Tires<br />
        <input type="radio" name="field" value="2" onclick='check_value(1, 2, "tire")'/> Dunlop Roadsmart Sport-Touring Tires<br />
        <input type="radio" name="field" value="3" onclick='check_value(2, 2, "tire")'/> Pirelli Scorpion Trail Tires<br />
    </form>
    
    <img id="imgBox2" src="#" style="display:none">
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm currently working on a website which is displaying users tweets from the twitter
I am currently working with check boxes and displaying values based on the values
I am currently working with radio buttons and check boxes to display images with
I'm currently working on a jQuery solution where I want to load images from
I am currently working on a GWT project where I am displaying an HTML
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
Currently i am working on a iPhone Application Which is displaying video. I have
I am currently working on an asp.net web page with a GridView displaying a
I currently have a working gridview displaying some thumbnails. Currently, when you select an

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.