Javascript continues to conceal my web background without my permission

After loading my webpage, I click on a link and the expected javascript runs as planned. However, once it completes and presents the results, the page goes blank to a white screen displaying only the outcomes. My goal is to have these results showcased on the webpage with the background intact. Despite numerous attempts, I have been unable to achieve this. Below is the code snippet in question:

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
<script type="text/javascript">
function myFunction()
{

var accountnum;
var beginningBal;
var itemsCharged;
var credits;
var creditLimit;
var sum;

accountnum = window.prompt("Enter the account number:");

beginningBal = window.prompt("Enter the beginning balance:");

itemsCharged = window.prompt("Total of all items charged:");

credits = window.prompt("Total credits applied to this account:");

creditLimit = window.prompt("Enter the credit limit: ");

var zero = parseInt (accountnum);
var first = parseInt(beginningBal);
var second = parseInt(itemsCharged);
var third = parseInt (credits);
var fourth = parseInt (creditLimit);
var sum = first + second - third;
var diff = fourth - sum;
if (sum < fourth)
{
    document.writeln("<h1>Your account number is:" + zero);
    document.writeln("<h1>Your beginning balance is: $" + first);
    document.writeln("<h1>Total of items charged: $" + second);
    document.writeln("<h1>Total credits applies to this account: $" + third);
    document.writeln("<h1>Your credit limit is: $" + fourth);
    document.writeln("<h1>Your account balance is: $" + sum);
    document.writeln("<h1>Your credit is: $" + diff);
    document.getElementById('output').innerHTML = html;

}
else if (sum > fourth)
{
    document.writeln("<h1>Your account number is:" + zero);
    document.writeln("<h1>Your beginning balance is: $" + first);
    document.writeln("<h1>Total of items charged: $" + second);
    document.writeln("<h1>Total credits applies to this account: $" + third);
    document.writeln("<h1>Your new account balance is: $" + sum);
    document.writeln("<h1>Your credit limit is: $" + fourth);
    document.writeln("<h1>Your new balance is: $" + diff);
    document.writeln("<h1>Your credit is exceeded!");
    document.getElementById('output').innerHTML = html;
}
else if (sum == fourth)
{
    document.writeln("<h1>Your account number is:" + zero);
    document.writeln("<h1>Your beginning balance is: $" + first);
    document.writeln("<h1>Total of items charged: $" + second);
    document.writeln("<h1>Total credits applies to this account: $" + third);
    document.writeln("<h1>Your account balance is: $" + sum);
    document.writeln("<h1>Your credit limit is: $" + fourth);
    document.writeln("<h1>Your new balance is: $" + diff);
    document.writeln("<h1>You are out of credit!");
    document.getElementById('output').innerHTML = html;
}
}

</script>
<style>
#output{
    height:43px;

}
html{
     background: url(images/nxerainbowgrid.jpg) no-repeat center center fixed;
     z-index:-9999; 
  -webkit-background-size: cover;
  -moz-background-size: cover;
  -o-background-size: cover;
  background-size: cover;
  filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='images/nxerainbowgrid.jpg', sizingMethod='scale');
-ms-filter: "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='images/nxerainbowgrid.jpg', sizingMethod='scale')";
}
</style>
</head>

<body>
<a href="#" onClick="myFunction()"><p>CLICK HERE TO HAVE FUN!!!</p></a>
<div id="output"></div>
</body>
</html>

Answer №1

It's not ideal or recommended to repeat code excessively. Instead, consider using a prompt for input. Here is a temporary solution:

Define the HTML structure and update the CSS style to target the body element. This will apply a background image to the entire page.

 var html;
 if(sum<forth){
    html ="<h1> Your account number is:" + zero + "</h1>";
    html ="<h1>Your beginning balance is: $" + first + "</h1>";
    html ="<h1>Total of items charged: $" + second + "</h1>";
    html ="<h1>Total credits applies to this account: $" + third + "</h1>";
    html ="<h1>Your credit limit is: $" + fourth + "</h1>";
    html ="<h1>Your account balance is: $" + sum + "</h1>";
    html ="<h1>Your credit is: $" + diff + "</h1>";
    document.getElementById('output').innerHTML = html;
}    


 body{
    background: url(index.jpeg) no-repeat center center fixed;
    /*keep all other. only change the tag name*/
}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Retrieve a Google map using Ajax in a PHP script

I'm attempting to display a google map on my homepage using the following function: function addressCode(id, concatenatedToShowInMap) { var geocoder; var map; geocoder = new google.maps.Geocoder(); ...

What is the best way to vertically align text that is positioned absolutely in the center?

I'm looking to implement a hover hide effect. Check out my inspiration on CodePen * { box-sizing: border-box; margin: 0; padding: 0; } body { background-color: #123456; } #object { background-color: cornsilk; border: #333 3px solid; ...

Looking for assistance in creating contemporary gallery labels?

I am in the process of creating a portfolio website and I want to showcase some of my work from middle school. However, I would like to add a label to differentiate it from my current work. The gallery features various images with different dimensions dis ...

Discovering the method to extract a Specific Form Field value with JQuery

Recently, I encountered a form that looked like this: <form id="post_comment" action="cmt.php" method="post"> <input type="hidden" name="type" value="sub" /> <textarea id="body"></textarea> </form> To interact with the ...

Make sure the 'card-title' is positioned directly before a div element

How can I align the 'title' to start right above 'first yeah', with the image positioned accordingly? https://i.sstatic.net/fyI2o.png I've attempted various methods (including using classes) but have been unsuccessful so far Her ...

Using regex, match any word along with the preserved white space and consider parentheses as a single word

I need help with creating a regex pattern to split a string of words in a specific way. The current pattern I've been using is (?!\(.*)\s(?![^(]*?\)), but it's not giving me the desired outcome. It's close, but not quite the ...

Ways to effectively manage multiple asynchronous operations while retrieving emails and attachments using IMAP and JavaScript

Currently, I am utilizing the IMAP library along with JavaScript to retrieve emails from a server. This is my approach: Retrieve emails based on email address, subject, and a specified time frame. Determine the total number of emails received. For each e ...

Attain the ability to distinguish errors in Promises

Context In my project, I have implemented a REST API that interacts with MongoDB using Node.js and Express. The issue at hand involves handling errors based on different scenarios when making requests to the NoSQL database. Challenge The current impleme ...

Trim the edges of a photo and add the Kinetic filter

Currently, I am utilizing Kinetic for image processing purposes. The issue arises when I crop an image and then attempt to convert it to black and white by clicking a button. Unfortunately, the straightforward setFilter function does not seem to work in th ...

Node.js version 12.7 does not have the ability to support dynamic keys within objects

According to what I've read about ecma6, it should allow for dynamic key objects. I recently upgraded my node to version 0.12.7, but I'm still encountering an error. node /var/www/games/node_modules/app.js /var/www/games/node_modules/app.js ...

Exploring discrepancies between two tables with the power of Javascript

const firstTable = document.getElementById('table_1') const secondTable = document.getElementById('table_2') const rows1 = firstTable.rows const rows2 = secondTable.rows for (let i = 0; i < rows1.length; i++) { for (let x in rows ...

Using a function with a parameter as an argument in an event handler

Imagine you have the code snippet below: $('#from').focus(listExpand(1)); $('#to').focus(listExpand(3)); I am facing an issue as the code is not behaving as expected. I believe the problem lies in passing a function result instead of ...

How can I set a checkbox as mandatory using ng-messages and Ionic framework?

I am currently developing a form for my application using Cordova CLI 8.0, Ionic 1.3.5, and AngularJS 1.5. My goal is to set a checkbox as required within the form. Here's the approach I have taken so far: <ion-checkbox name="entry.exportcode" n ...

What factors influence the timing of Chrome's spell-check feature for a particular word?

Currently, I am troubleshooting a bug in our code that is related to text input behavior. The issue at hand is that in one field, when you start typing on Chrome, the word does not get red underlined until you press space. However, in another field, Chrom ...

Alert: MongoDBError: Timeout occurred while buffering operation `users.insertOne()` for 10 seconds

While running MongoDB Atlas on node express, I encountered an error when testing with Postman. const express = require('express'); const cors = require('cors'); const mongoose = require('mongoose'); require('dotenv' ...

Clicking on the overlaying divs in the slideshow does not trigger any changes when clicked

My question is about the behavior of the href attribute in a fade-style animation. Even when different containers are visible, the href value remains constant. Below is the HTML code: <div id="teaserslider"> <ul> <li> ...

The concept of nested views in Angular UI-Router allows for a

How can I successfully implement nested views, where after logging in the user is redirected to in.html, and all links within in.html are directed to a ui-view? Currently, all links redirect to a new page. index.html <!-- more HTML --> <body ng- ...

What is the best way to implement Angular 2 slash routes in conjunction with Node Express?

I have defined some routes in my App component: @routeConfig([ { path:'login', name: 'Login', component: Login }} Additionally, I have a basic node express loader set up: var express = require('express'); var ...

Is it possible to utilize retina images with CSS3's :before selector?

Can I adjust the size of an image inserted using :before? For example, if I want to use a high resolution image in the content below - how can I specify the dimensions? .buy_tickets_btn:before{ content: url(../images/buttons/pink_ticket_btn_bg.pn ...

Turn off the background when the automatic popup box appears

I have implemented a popup box that automatically appears after 5 seconds when the site is loaded. However, if I click outside of the popup box, it closes. I want to disable the background when the popup box is displayed. If I remove the two lines of code ...