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

  • Home
  • SEARCH
  • 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 7805849
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T02:20:35+00:00 2026-06-02T02:20:35+00:00

working on a mini page for some homework and I’m stuck! What we’ve been

  • 0

working on a mini page for some homework and I’m stuck! What we’ve been told to do it to pull localStorage variables from a fake “registration” page we’ve made (which gets it’s information from a user’s choice of three radio buttons) and use that information to alter what the user will see on a fake, very basic “e-commerce” site.

What I’ve successfully done is wire my button from the registration page to open the e-commerce page upon click and I think I’ve properly coded in storing the variables of choice. Here’s my “registration page” code:

window.onload=init;
//setup commands
function init () {
    //wire button to function

    var submitButton=document.getElementById("submitButton");
    submitButton.onclick= travel;
    }   
function travel () {
    window.location="etzy.html"

    if (document.getElementById("Dog").checked) 
        localStorage.usercomputer = "Dog";
    else if (document.getElementById("Cat").checked) 
        localStorage.usercomputer = "Cat";
    else if (document.getElementById("Black").checked) 
        localStorage.usercomputer = "Black";
    else if (document.getElementById("Brown").checked) 
        localStorage.usercomputer = "Brown";
    else if (document.getElementById("White").checked) 
        localStorage.usercomputer = "White";
    else if (document.getElementById("Yes").checked) 
        localStorage.usercomputer = "Yes";
   else if (document.getElementById("No").checked) 
        localstorage.usercomputer = "No";
    }

Okay, so there’s that. And then here’s the e-commerce JS I’ve started working on:

window.onload=image;
    function image (){
    var images = document.getElementById("localStorage.usercomputer");

       if (images ="Dog"){
        //document.write('<img class="etsyimage" src="dog.jpg" alt="dog Image"/>');
             alert("dog");
       }
       else if (images ="Cat"){
        //document.write('<img class="etsyimage" src="cat.jpg" alt="cat Image" />');
            alert("cat");
        }
    }

I’ve commented out the document.write and put in an alert to test. Problem is, I keep getting the “Dog” alert when I test it (and choose “Cat”) and I have no idea why. So thus follows are some of my questions:
1) Why am I only getting the “Dog” alert and how can I fix that?
2) When I wasn’t using the alert and tried out the document.write function, the image ‘dog.jpg’ would overwrite all of the other HTML information on the page (banner, menu, etc.). Is there some way to fix this or use something other than document.write to put an image on the resulting page (HTML) but to not have it supersede everything else on the HTML so that it’s blank except for the new image?

I think those are my only questions in that if that stuff can be fixed then everything would be functional at least. Sorry for the novel of a post. Also feel free to judge the base-level javascript code and questions, I’m new to this so I’m just sort of struggling my way through as of now.
Thank you!

  • 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-02T02:20:36+00:00Added an answer on June 2, 2026 at 2:20 am

    In your image() function your if statement is incorrect

    window.onload=image;
        function image (){
        var images = document.getElementById("localStorage.usercomputer");
    
           if (images == "Dog") //Need two ='s for comparison
           { 
                 alert("dog");
           }
           else if (images == "Cat")
           {
                alert("cat");
           }
       }
    

    Using one = in javascript will assign values (i.e var bob = 'a person'), hence your function throwing up unexpected results. when testing values always use == or === for strict comparison to check if values are equal and of the same type.

    In answer to your other question, I would add a container or area on the other page where you want the image to go. Perhaps using <div id="imgDiv"></div> tags and give it an ID as i’ve shown. You can style and position the div using CSS and then apend the image to this container rather than using document.write(). Something like the code below

    window.onload=image;
        function image (){
        var images = document.getElementById("localStorage.usercomputer");
        var imgDiv = document.getElementById("imgDiv"); //setup variable to img container        
    
       if (images == "Dog")
       { 
             imgDiv.innerHTML = '<img class="etsyimage" src="dog.jpg" alt="dog image" />';    
       }
       else if (images == "Cat")
       {
            imgDiv.innerHTML = '<img class="etsyimage" src="cat.jpg" alt="cat image" />';
       }
    }
    

    Hope this helps

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

Sidebar

Related Questions

I am working on a little mini compiler while trying to learn some MIPS
Recently, i am working with jquery for my mini-project. I took a code from
Has anyone been able to get the MVC mini profiler working on IIS 6?
I've been working on a very simple Jquery script that displays a few mini-dashboards
I have been working on a site that makes some pretty big use of
I'm having an IE7 issue with a website i'm working on - www.mini-meals.co.uk Basically,
Working on an iPhone application through a TightVNC connection into a Mac Mini; the
I am working on a mini-shell, and am trying to set the execution path
I am working on making a mini app using Json parsing . Output I
I'm working on a kind of dashboard mini site that has blocks with a

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.