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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T08:45:59+00:00 2026-05-26T08:45:59+00:00

My homework is to create a web page that displays an image and a

  • 0

My homework is to create a web page that displays an image and a drop down list, using a javascript switch statement. The code is written so that when a selection in the drop down list is made the image on the page will change to reflect the selection and an alert box will display a unique message for the selected image. I created switch case statements with a break between each case. The last case is a default with it’s own alert message. I declared a global variable. In the body section I gave the select element id’s and values for each option. You will see a function above the switch case statement commented out because it didn’t work. None of the other cases nor their alerts display. But the code partially works. The page image and the drop down list displays. I just can’t seem to get the image to change and the alert boxes to display. I’ve been at it for at least twenty hours yesterday and today. I could use some help. Suggestions? Since yesterday I’ve tried using multiple parameters in the function as well as in the switch. What happens is that the alert boxes stop displaying or go to default. I’m thinking the answer to change the page content i.e. the images in the drop down list may be in the form. I tried document.getElementById(“pic”).value and used it in the function and in the switch but it didn’t work. So I’m stumped. Here is my changes. If anybody can give me some more hints, I’d appreciate. Like I said everything works except the page content is not changing in the switch.

Here is the link http://ciswebs.smc.edu/cis54/tyson_schweidel/SwitchSunGuy.htm
and the code:

The code sections are javascript which contain the switch case statement. The body sections contains the select element which is the drop down menu.

var inobj,sunPic;
function changepic(inobj, sunPic) {

 switch (inobj){

 case "0":
    sunPic ="1";
    alert("Please make a selection or go back to bed.");
    break;

  case "1":
    document.getElementById("pic").innerHTML = 2;
    alert("I am glad you are happy.");
    break;

  case "2":
   sunPic ="3";
    alert("I am sorry you are sad.");
    break;

  case "3":
   sunPic= "4";
    alert("It is great you are feeling cool.");
    break;

  case "4":
   sunPic= "5";
    alert("I hope you get past that soon.");
    break;
  default:
    alert("You need to fix something!");
    break;
  }
  } 


  </script>
</head>
<body>
<img src="items/Sun0.jpg" id="pic" alt="A funny face with question mark above.">
<p> Make selection to change the image.</p>
<form name = "sunPic" action="">
<select name="sunPic" onChange="changepic(this.value);">
<option  alt="funny face" value="0">Select</option>
<option  alt="happy face" value="1">Happy</option>
<option  alt="sad face"   value="2">Sad</option>
<option  alt="cool face"  value="3">Cool</option>
<option  alt="puzzled face" value="4">Unsure</option>
</select>
</form>
</body>
<html>
  • 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-05-26T08:46:00+00:00Added an answer on May 26, 2026 at 8:46 am

    I fixed the select below — I did not change it to make a different picture (since you did not give urls). I’ll that part of it to you — but maybe this will help with the frustration. NOTE: There can only be one id of any given value on a page.

    Here is the working fiddle: http://jsfiddle.net/KdebH/

    <img src="items/Sun0.jpg" id="pic" alt="A funny face with question mark above.">
    <p> Make selection to change the image.</p>
    <select onChange="changepic(this.value);">
        <option  alt="funny face" value="0">Select</option>
        <option  alt="happy face" value="1">Happy</option>
        <option  alt="sad face"   value="2">Sad</option>
        <option  alt="cool face"  value="3">Cool</option>
        <option  alt="puzzled face" value="4">Unsure</option>
    </select>
    
    
    function changepic(inobj) {
    
    
        switch (inobj) {
    
        case "0":
            sunPicture = 1;
            alert("Please make a selection or go back to bed.");
            break;
    
        case "1":
            sunPicture = 2;
            alert("I am glad you are happy.");
            break;
    
        case "2":
            sunPicture = 3;
            alert("I am sorry you are sad.");
            break;
    
        case "3":
            sunPicture = 4;
            alert("It is great you are feeling cool.");
            break;
    
        case "4":
            sunPicture = 5;
            alert("I hope you get past that soon.");
            break;
        default:
            alert("You need to fix something!");
            break;
        }
    
    
    }
    

    Next steps:

    for each case in the switch add code to

    • find the image in the dom
    • change the src attribute to point at the new image.

    then you are done.

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

Sidebar

Related Questions

I'm trying to create a program for homework that displays a Tic-Tac-Toe board, and
For homework I am supposed to create a circularly linked list using nodes and
I'm trying to create a deck of cards for my homework. Code is posted
I'm working on a homework project that requires me to create an object from
For homework, I'm trying to create a CustomButton that has a frame and in
This is/isn't homework...the printing of the list IS homework and that works great, the
So for Homework I have to create this program that reads from a text
For my homework assignment, I have to create a linked list and it must
As part of a homework assignment, we are supposed to create an array that
I'm working on a homework assignment that asks me to create a calculator that

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.