How to add two decimal places to an array of objects

The array looks like this:

const arr = [
    {title: 'Cat1', val1: '0', val2: '20'},
    {title: 'Cat2', val1: '0', val2: '30'},
]

I need the val1 and val2 to be converted into a number with two decimal places (eg. 0.00, 20.00), and then be able to pass the treated array (that includes everything else) in a different function.

Golang reads html tags () from JSON string data as &lt and &gt which causes rendering issues in the browser

I have a basic web server that renders blog posts from a database of JSON posts wherein the main paragraphs are built from a JSON string array. I was trying to find a way to easily encode new lines or line breaks and found a lot of difficulty with how the encoding for these values changes from JSON to GoLang and finally to my HTML webpage. When I tried to encode my JSON with newlines I found I had to encode them using \n rather than just n in order for them to actually appear on my page. One problem however was they simply appeared as text and not line breaks.

I then tried to research ways to replace the n portions of the joined string array into <br> tags, however I could not find any way to do this with go and moved to trying to do so in javascript. This did not work either despite me deferring the calling of my javascript in my link from my HTML. this is that javascript:

var title = window.document.getElementById("title");
var timestamp = window.document.getElementById("timestamp");
var sitemap = window.document.getElementById("sitemap");
var main = window.document.getElementById("main");
var contact_form = window.document.getElementById("contact-form");
var content_info = window.document.getElementById("content-info");

var str = main.innerHTML;

function replaceNewlines() {
    // Replace the n with <br>
    str = str.replace(/(?:rn|r|n)/g, "<br>");

    // Update the value of paragraph
    main.innerHTML = str;
}

Here is my HTML:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Dynamic JSON Events</title>
    <link rel="stylesheet" href="/blogtemplate.css"></style>
</head>
<body>
    <section id="title">
        <h1 id="text-title">{{.Title}}</h1>
        <time id="timestamp">
            {{.Timestamp}}
        </time>
    </section>
    <nav role="navigation" id="site-nav">
        <ul id="sitemap">
        </ul>
    </nav>
    <main role="main" id="main">
        {{.ParsedMain}}
    </main>
    <footer role="contentinfo" id="footer">
        <form id="contact-form" role="form">
        <address>
            Contact me by <a id="my-email" href="mailto:[email protected]" class="my-email">e-mail</a>
        </address>
        </form>
    </footer>
<script defer src="/blogtemplate.js">
</script>
</body>
</html>

I then finally turned to trying to hardcode <br> tags into my json data to discover that this simply renders as &lt and &gt when it finally reaches the browser. I am getting pretty frustrated with this process of encoding constantly causing me issues in creating newlines and line breaks. How can I easily include newlines where I want in my JSON string data?

Here is my Go script if it helps:

package main

import (
    "encoding/json"
    "html/template"
    "log"
    "net/http"
    "os"
    "regexp"
    "strings"
)

type BlogPost struct {
    Title      string   `json:"title"`
    Timestamp  string   `json:"timestamp"`
    Main       []string `json:"main"`
    ParsedMain string
}

// this did not seem to work when I tried to implement it below
var re = regexp.MustCompile(`rn|[rnvfx{0085}x{2028}x{2029}]`)
func replaceRegexp(s string) string {
    return re.ReplaceAllString(s, "<br>n")
}

var blogTemplate = template.Must(template.ParseFiles("./assets/docs/blogtemplate.html"))

func blogHandler(w http.ResponseWriter, r *http.Request) {
    blogstr := r.URL.Path[len("/blog/"):] + ".json"

    f, err := os.Open("db/" + blogstr)
    if err != nil {
        http.Error(w, err.Error(), http.StatusNotFound)
        return
    }
    defer f.Close()

    var post BlogPost
    if err := json.NewDecoder(f).Decode(&post); err != nil {
        http.Error(w, err.Error(), http.StatusInternalServerError)
        return
    }

    post.ParsedMain = strings.Join(post.Main, "")

    // post.ParsedMain = replaceRegexp(post.ParsedMain)

    if err := blogTemplate.Execute(w, post); err != nil {
        log.Println(err)
    }
}

func teapotHandler(w http.ResponseWriter, r *http.Request) {
    w.WriteHeader(http.StatusTeapot)
    w.Write([]byte("<html><h1><a href='https://datatracker.ietf.org/doc/html/rfc2324/'>HTCPTP</h1><img src='https://external-content.duckduckgo.com/iu/?u=https%3A%2F%2Ftaooftea.com%2Fwp-content%2Fuploads%2F2015%2F12%2Fyixing-dark-brown-small.jpg&f=1&nofb=1' alt='Im a teapot'><html>"))
}

func faviconHandler(w http.ResponseWriter, r *http.Request) {
    http.ServeFile(w, r, "./assets/art/favicon.ico")
}

func main() {
    http.Handle("/", http.FileServer(http.Dir("/assets/docs")))
    http.HandleFunc("/blog/", blogHandler)
    http.HandleFunc("/favicon.ico", faviconHandler)
    http.HandleFunc("/teapot", teapotHandler)
    log.Fatal(http.ListenAndServe(":8080", nil))
}

Here is an example of my JSON data:

{
    "title" : "Finished My First Blog App",
    "timestamp": "Friday, March 18th, 11:39 AM",
    "main": [
        "It took me awhile to tidy everything up but I finally finished creating my first ",
        "blog app using Go along with JSON for my database. I plan on using this to document ",
        "my own thoughts and experiences as a programmer and cybersecurity researcher; things ",
        "like tutorials, thought-pieces, and journals on my own projects progress will be ",
        "posted here. I look forward to getting more used to writing and sharing my own story, ",
        "I think it will help me learn from doing and also hearing feedback from others.\n\n",
        "I utilized a handler function to dynamically read from my JSON database and template ",
        "data into my HTML template using the go html/template package as well as the encoding/json ",
        "to handling reading those objects. Next I had to make sure my CSS and JavaScript assets ",
        "would be served alongside this finished template in order for my styling to be output into ",
        "the browser. For this I used a FileServer function which allowed for me to serve linked ",
        "resources in my HTML boilerplate and have the server still locate blog resources dynamically. ",
        "Going forward I am looking to add better styling, more JavaScript elements to the page, and ",
        "more functionality to how my JSON data is encoded and parsed in order to create more complex ",
        "looking pages and blog posts."
    ]
}

I am just trying to find a way to easily include spaces between paragraphs in the long array of strings in my JSON however I have failed in Go, my JS doesn’t ever seem to affect my webpage(this is not the only problem I have had with this, it does not seem to want to affect any page elements for some reason), and I cannot seem to hardcode <br> tags directly into my JSON as the browser interprets those as &lt;br&gt;&lt;br&gt;. Nothing I have tried has actually let me encode linebreaks, What can I do here?

Why should I use refs in React when I can perform the operation using getElementById?

I was reading the docs Refs and the DOM and A complete guide to React refs to better understand the concept of refs in React. However, I am not sure why the concept is needed when it can be solved in the vanilla JS way.

For example, in the 2nd link mentioned above, the author of the article says that React does not provide an easy way to auto-focus a text element and that in such a scenario, refs would come in handy. To check that, I was experimenting with alternative methods to achieve the same auto-focus without refs. Here is a part of my solution:

class ExampleComponent extends Component {
  .
  .
  .
  componentDidMount () {
    // accessing an element without using refs
    const element = document.getElementById(this.inputId);

    if (element) {
      element.focus();
    }
  }
  .
  .
  .
  render () {
    return (
      <input id={this.inputId} onChange={this.handleChange} value={this.state.value} />
    );
  }
}

And it works.

How are refs better than the solution above? It seems pretty simple to me but I might be missing out on something.

Thanks in advance.

Adding the 2nd timestamp shows this error failed to fetch data TypeError: Cannot read properties of undefined (reading ‘seconds’)

If I add the editedAt, it will throw this error:

failed to fetch data TypeError: Cannot read properties of undefined (reading 'seconds')

however, if I remove the data where it has the timestamp value of editedAt from the database. This will not cause an error. Is this because not all of the data have timestamp value of editedAt?

How do I fix this error since I need to display the data with the editedAt as well?

And this is the data:

const data = [
  {
    createdDate: { seconds: 1647660530, nanoseconds: 228000000 },
    id: "4jnEbtIGLKTgEnJYX7ci"
  },
  {
    editedAt: { seconds: 1647665687, nanoseconds: 627000000 },
    id: "vBBeIQsNbqvbqVWNIK6k"
  },
  {
    createdDate: { seconds: 1646370332, nanoseconds: 678000000 },
    id: "Hs29gnvfeD0cSQkNmsRn"
  },
  {
    createdDate: { seconds: 1645840425, nanoseconds: 486000000 },
    id: "gagdiaihdihaihsd"
  }
];

These are the codes:

 const columns = [
    {
      name: "createdDate",
      label: "Date",
      options: {
        filter: true,
        sort: true,
        customBodyRender: (value, tableMeta, updateValue) => {
          return new Date(value.seconds * 1000).toLocaleDateString();
        },
      },
    },
    {
      name: "editedAt",
      label: "Date",
      options: {
        filter: true,
        sort: true,
        customBodyRender: (value, tableMeta, updateValue) => {
          return new Date(value.seconds * 1000)?.toLocaleDateString();
        },
      },
    },
  ];

How to display radio button value on checked (not on clicked). *or pls guide me if there is better way for ecommerce product page*

I’m creating an ecommerce website and I’m having issue on the pricing of product page based on radio (product) button.

Issue 1 – the price is not displayed when the page is loaded
enter image description here

Issue 2 – the price displayed has lots of decimal point (I tried used number_format(“price”,2) but it couldn’t be displayed)
enter image description here

Below are the codes of the page

code

  window.addEventListener('DOMContentLoaded', function() {
  const groups = [...document.querySelectorAll(".swatch")].slice(1); // drop the first div
  document.getElementById("container").addEventListener("click", function(e) {
    const tgtDiv = e.target.closest(".swatch-element")
    if (tgtDiv) {
      const groupId = tgtDiv.querySelector("input[type=radio]").dataset.group;
      groups.forEach(aGroup => aGroup.classList.toggle("hide", groupId !== aGroup.id))

    }
  });
});
    function check() {
        $("#swatch-1-9").prop("checked", true);
    }
    function check2() {
        $("#swatch-1-6").prop("checked", true);
    }
    function check3() {
        $("#swatch-1-4").prop("checked", true);
    }
    function check4() {
        $("#swatch-1-1").prop("checked", true);
    }

        function displayRadioValue() {
            var ele = document.getElementsByName('length');
            
            for(i = 0; i < ele.length; i++) {
                if(ele[i].checked)
                document.getElementById("price").innerHTML
                        = "RM " + ele[i].value*<?php echo $product['wesell'];?>
                            
                        ;
            }
        }
  
.swatch {
  margin: 1em 0;
  display:flex;
  flex-flow: row;
}
.header { width:70px}
.hide { display: none; }

.swatch .header {
  margin: 0.5em 0;
}

.swatch input {
  display: none;
}

.swatch label {
  -webkit-border-radius: 2px;
  -moz-border-radius: 2px;
  border-radius: 2px;
  float: left;
  min-width: 50px;
  height: 35px;
  margin: 0;
  border: #ccc 1px solid;
  background-color: #ddd;
  font-size: 13px;
  text-align: center;
  line-height: 35px;
  white-space: nowrap;
  text-transform: uppercase;
}

.swatch-element label {
  padding: 0 10px;
}

.color.swatch-element label {
  padding: 0;
}

.swatch input:checked+label {
  -webkit-box-shadow: 0px 1px 2px rgba(0, 0, 0, 0.8);
  -moz-box-shadow: 0px 1px 2px rgba(0, 0, 0, 0.8);
  box-shadow: 0px 1px 2px rgba(0, 0, 0, 0.8);
  border-color: transparent;
}

.swatch .swatch-element {
  float: left;
  -webkit-transform: translateZ(0);
  -webkit-font-smoothing: antialiased;
  margin: 0px 10px 10px 0;
  position: relative;
}

.crossed-out {
  position: absolute;
  width: 100%;
  height: 100%;
  left: 0;
  top: 0;
}

.swatch .swatch-element .crossed-out {
  display: none;
}

.swatch .swatch-element.soldout .crossed-out {
  display: block;
}

.swatch .swatch-element.soldout label {
  filter: alpha(opacity=60);
  -khtml-opacity: 0.6;
  -moz-opacity: 0.6;
  opacity: 0.6;
}

.swatch .tooltip {
  text-align: center;
  background: gray;
  color: #fff;
  bottom: 100%;
  padding: 10px;
  display: block;
  position: absolute;
  width: 100px;
  left: -23px;
  margin-bottom: 15px;
  filter: alpha(opacity=0);
  -khtml-opacity: 0;
  -moz-opacity: 0;
  opacity: 0;
  visibility: hidden;
  -webkit-transform: translateY(10px);
  -moz-transform: translateY(10px);
  -ms-transform: translateY(10px);
  -o-transform: translateY(10px);
  transform: translateY(10px);
  -webkit-transition: all .25s ease-out;
  -moz-transition: all .25s ease-out;
  -ms-transition: all .25s ease-out;
  -o-transition: all .25s ease-out;
  transition: all .25s ease-out;
  -webkit-box-shadow: 2px 2px 6px rgba(0, 0, 0, 0.28);
  -moz-box-shadow: 2px 2px 6px rgba(0, 0, 0, 0.28);
  -ms-box-shadow: 2px 2px 6px rgba(0, 0, 0, 0.28);
  -o-box-shadow: 2px 2px 6px rgba(0, 0, 0, 0.28);
  box-shadow: 2px 2px 6px rgba(0, 0, 0, 0.28);
  z-index: 10000;
  -moz-box-sizing: border-box;
  -webkit-box-sizing: border-box;
  box-sizing: border-box;
}

.swatch .tooltip:before {
  bottom: -20px;
  content: " ";
  display: block;
  height: 20px;
  left: 0;
  position: absolute;
  width: 100%;
}

.swatch .tooltip:after {
  border-left: solid transparent 10px;
  border-right: solid transparent 10px;
  border-top: solid gray 10px;
  bottom: -10px;
  content: " ";
  height: 0;
  left: 50%;
  margin-left: -13px;
  position: absolute;
  width: 0;
}

.swatch .swatch-element:hover .tooltip {
  filter: alpha(opacity=100);
  -khtml-opacity: 1;
  -moz-opacity: 1;
  opacity: 1;
  visibility: visible;
  -webkit-transform: translateY(0px);
  -moz-transform: translateY(0px);
  -ms-transform: translateY(0px);
  -o-transform: translateY(0px);
  transform: translateY(0px);
}

.swatch.error {
  background-color: #E8D2D2!important;
  color: #333!important;
  padding: 1em;
  border-radius: 5px;
}

.swatch.error p {
  margin: 0.7em 0;
}

.swatch.error p:first-child {
  margin-top: 0;
}

.swatch.error p:last-child {
  margin-bottom: 0;
}

.swatch.error code {
  font-family: monospace;
}
<div class="swatch color clearfix" id="container" data-option-index="0">
  <div class="header">
    Product
  </div>
  <div data-value="black" class="swatch-element color black available">
    <div class="tooltip">black</div>
    <input id="swatch-0-black" checked name="option-0" value="0.96" type="radio" data-group="group1" checked onclick="displayRadioValue()   ">
    <label for="swatch-0-black" style="background-color: black; background-image: url(./assets/images/black.png)"><img class="crossed-out" src="./assets/images/soldout.png" alt=""></label>
  </div>
  <div data-value="red" class="swatch-element color red available">
    <div class="tooltip">
      red
    </div>
    <input id="swatch-0-red" name="option-0" value="1.34" type="radio" data-group="group2" onclick="check2(),displayRadioValue()">
    <label for="swatch-0-red" style="background-color: red; background-image: url(./assets/images/red.png)">
                        <img class="crossed-out" src="./assets/images/soldout.png" alt="">
                        </label>
  </div>
  <div data-value="white" class="swatch-element color white available">
    <div class="tooltip">
      white
    </div>
    <input id="swatch-0-white" name="option-0" value="1.48" type="radio" data-group="group3" onclick="check3(),displayRadioValue()">
    <label for="swatch-0-white" style="background-color: white; background-image: url(./assets/images/white.png)">
                        <img class="crossed-out" src="./assets/images/soldout.png" alt="">
                        </label>
  </div>
  <div data-value="blue" class="swatch-element color blue available">
    <div class="tooltip">
      blue
    </div>
    <input id="swatch-0-blue" name="option-0" value="1.52" type="radio" data-group="group4" onclick="check4(),displayRadioValue()">
    <label for="swatch-0-blue" style="background-color: blue; background-image: url(./assets/images/blue.png)">
                        <img class="crossed-out" src="./assets/images/soldout.png" alt="">
                        </label>
  </div>
</div>

<div class="swatch clearfix" data-option-index="1" id="group1">
  <div class="header">
    Weight
  </div>
  <div data-value="small" class="swatch-element small available">
    <input id="swatch-1-9" name="length" value="0.96" type="radio" id="group4a"  checked  onclick="displayRadioValue()">
    <label for="swatch-1-9">
                        0.96g <img class="crossed-out" src="./assets/images/soldout.png" alt="">
                        </label>
  </div>

</div>

<div class="swatch clearfix hide" id="group2">
  <div class="header">
    Weight
  </div>
  <div data-value="small" class="swatch-element small available">
    <input id="swatch-1-6" name="length" value="1.34" type="radio"  onclick="displayRadioValue()">
    <label for="swatch-1-6">
      1.34g
    </label>
  </div>
  <div data-value="medium" class="swatch-element medium available">
    <input id="swatch-1-7" name="length" value="1.44" type="radio" id="group3b" onclick="displayRadioValue()">
    <label for="swatch-1-7">
      1.44g 
    </label>
  </div>
  <div data-value="medium" class="swatch-element medium available">
    <input id="swatch-1-8" name="length" value="1.54" type="radio" id="group3c" onclick="displayRadioValue()">
    <label for="swatch-1-8">
      1.54g 
    </label>
  </div>
  
</div>

<div class="swatch clearfix hide" id="group3">
  <div class="header">
    Weight
  </div>
  <div data-value="small" class="swatch-element small available">
    <input id="swatch-1-4" name="length" value="1.48" type="radio" onchange="displayRadioValue()">
    <label for="swatch-1-4">
                        1.48g 
                        </label>
  </div>
  <div data-value="medium" class="swatch-element medium available">
    <input id="swatch-1-5" name="length" value="1.49" type="radio" id="group2b" onclick="displayRadioValue()">
    <label for="swatch-1-5">
                        1.49g <img class="crossed-out" src="./assets/images/soldout.png" alt="">
                        </label>
  </div>
</div>

<div class="swatch clearfix hide" id="group4">
  <div class="header">
    Weight
  </div>
  <div data-value="small" class="swatch-element small available">
    <input id="swatch-1-1" name="length" value="1.52" type="radio"  onclick="displayRadioValue()">
    <label for="swatch-1-1">
                        1.52g
                        </label>
  </div>
  <div data-value="medium" class="swatch-element medium available">
    <input id="swatch-1-2" name="length" value="1.54" type="radio" onclick="displayRadioValue()">
    <label for="swatch-1-2">
                        1.54g 
                        </label>
  </div>
  <div data-value="medium" class="swatch-element medium available">
    <input id="swatch-1-3" name="length" value="1.57" type="radio" onclick="displayRadioValue()">
    <label for="swatch-1-3">
                        1.57g
                        </label>
  </div>
</div>

    <div id="purchase-1293235843">
    <div class="detail-price" itemprop="price">
      <span class="price" id="price">

      </span>
    </div>
  </div>

JS userscript Refused to connect because it violates the following content security policy directive [duplicate]

I am writing a tampermonkey script in JS that fetches data from google sheets.

 const url = 'https://docs.google.com/spreadsheets/d/...';
    await fetch(url)
    .then(res => res.text())
    .then(rep =>{
        data = JSON.parse(rep.substr(47).slice(0,-2));
        console.log(data);

I am getting the following error

Refused to connect to 'https://docs.google.com/spreadsheets/d/...' because it violates the following Content Security Policy directive: "connect-src 'self'

How do I fix this?

Nested Iframe doesn’t have content after reload on Mozilla

I have this problem on Mozilla (worked perfectly on Chrome) where the nested Iframe doesnt have content after reload (only empty header and body tag)

Somehow you can click on the search bar and enter (instead of reload) to open again and all iFrame will load as intended

The snippet below doesnt work on the playcode website. You should open it in localhost for it to work.
https://playcode.io/874440/

Body index.html

<body>
    <div>Index</div>
    <iframe id="iframe"></iframe>
    <script>
        (function () {
            var b = document.getElementById("iframe");
            b.setAttribute("src", "iframe.html?" + Math.random() * 100);
        })();
        window.addEventListener('beforeunload', function (event) {
            console.log('I am the 1st one.');
        });
        window.addEventListener('unload', function (event) {
            alert('unLoad')
        });
    </script>
</body>

body iframe.html

<body>
    <header>
        IFRAME1
    </header>
    <iframe id="iframe2"></iframe>
    <script>
        (function () {
            var b = document.getElementById("iframe2");
            b.setAttribute("src", "iframe2.html?" + Math.random() * 100);
        })();
        window.addEventListener('beforeunload', function (event) {
            console.log('frame 1 before unload.');
        });
        window.addEventListener('unload', function (event) {
            console.log('frame 1 unload.');
        });
        window.addEventListener('pagehide', (event) => {
            if (event.persisted === true) {
                console.log('This page *might* be entering the bfcache.');
            } else {
                console.log('This page will unload normally and be discarded.');
            }
        });
    </script>
</body>

Body iframe2.html

<body>
    <header id="h2">
        this is iframe 2
    </header>
    <script src="iframe2.js"></script>
</body>

I read something about bfcache, which is why i tried to put unload event to negate bfcache.

It seems thats not the issue.

Merging number of shapes to make a single svg element

Basically, its for performance improvement. In SVG, the more the number of elements, the less performance efficient it gets, or in simpler words, fps drops. I am trying to improve some performance issues in my SVG illustration library (ChelseaJS) when it comes to a large number of elements. Is there a way, I could merge shapes, for example, instead of two rectangle elements, it can be just one element.
ps: don’t suggest the tag, coz, it’s just like a box for keeping elements together.

Function to remove special character

I am new in programming. I need an example for a funciton that I need to do to learn. The function is below.

  • a function that accepts input from a user.
  • Then when the user submits this function will return a sorted arrangement that removes allspaces and symbols
  • then sorts ascending for alphabets on the left side and sorts descending for numerics.

Can I do all this in one string? better to be in HTML or JS? I need to see any.

I am having a problem to make my text delay, for that I am using setTimeout function [duplicate]

Please help me and tell how can I fix this problem
I have tried changing the format a lot but this problem is still there, actually I am beginner who has leant web developing from the internet only.

Here’s my code of html, css and JavaScript –

**HTML**
<div class="sub-heading">
      <h3>Wants high quality fini....... This place is for you</h3>
    </div>

**CSS**
.sub-heading {
  display: flex;
  justify-content: center;
  align-items: center;
  margin: auto;
  transition: 3s;
  visibility: hidden;
}

**JavaScript**
let myTimeOut = setTimeout(myFunction, 3000);

function myFunction() {
    document.getElementsByClassName("sub-heading").style.visibility = "visible";
}

Please help me and tell how can I fix this problem
I have tried changing the format a lot but this problem is still there, actually I am beginner who has leant web developing from internet only.

JavaScript Event Handling – Select not changing

I am attempting to use JavaScript to change the image that is displayed based on the option selected from a dropdown menu.

Using chrome monitorevents() I am able to tell that the change event is being triggered, however the variable direction is not being changed.

If I change the assigned value of direction manually, as you can see commented out, the correct image will display.

I’m sure it’s something minor I’m overlooking, but I’ve been noodling at this pretty much all day.

I would appreciate anyone’s input.


    <div class="dropdown">
        <label for="choose-lighting" id="windowDirection">Which direction does your window face?</label>

        <select name="lighting" id="choose-lighting">
            <option value="empty">--- Direction ---</option>
            <option value="north">North</option>
            <option value="south">South</option>
            <option value="east">East</option>
            <option value="west">West</option>
        </select>
    </div>

    <div id="displayBox">
        <img src="" id="onDisplay">
    </div>

    <script>
        // var direction = document.querySelector("select");
        // var onDisplay = document.getElementById("onDisplay")
        var select = document.getElementById("choose-lighting");
        var direction = select.options[select.selectedIndex].text;
        console.log(direction);
        // var direction = "south";

        function chooseLighting() {

            // switch (direction) {
            //     case "north":
            //         document.getElementById("onDisplay").src = "images/lightguide_north.jpg";
            //         break;
            //     case "south":
            //         document.getElementById("onDisplay").src = "images/lightguide_south.jpg";
            //         break;
            //     case "east":
            //         document.getElementById("onDisplay").src = "images/lightguide_east.jpg";
            //         break;
            //     case "west":
            //         document.getElementById("onDisplay").src = "images/lightguide_west.jpg";
            //         break;
            //     default:
            //         document.getElementById("onDisplay").src = "images/lightguide_genericweb.jpg";
            //         break;
            // }

            if(direction == "North") {
                document.getElementById("onDisplay").src = "images/lightguide_north.jpg";
            }

            else if(direction == "South") {
                document.getElementById("onDisplay").src = "images/lightguide_south.jpg";
            }

            else if(direction == "East") {
                document.getElementById("onDisplay").src = "images/lightguide_east.jpg";
            }

            else if(direction == "West") {
                document.getElementById("onDisplay").src = "images/lightguide_west.jpg";
            }

            else {
                document.getElementById("onDisplay").src = "images/lightguide_genericweb.jpg";
            }

        }

        if (window.addEventListener) {
            window.addEventListener("load", chooseLighting, false);
        }

        else if (window.attachEvent) {
            window.attachEvent("onload", chooseLighting);
        }

        if (document.getElementById("choose-lighting").addEventListener) {
            document.getElementById("choose-lighting").addEventListener("change", chooseLighting, false);
            console.log(direction);
        }

        else if (document.getElementById("choose-lighting").attachEvent) {
            document.getElementById("choose-lighting").attachEvent("onchange", chooseLighting);
            console.log(direction);
        }

    </script>