0

I've got a couple of forms on HTML giving a variable to each other. My plan is to show a sort of "receipt" to display what is being purchased.

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
</head>

<body>
<p>Review Purchases</p>
<p id="recipt"></p>
<button onClick="refresh()" type="button">Refresh</button>
<p><a href="Payment.html">PAY NOW</a></p>
    
</body>
<script>
    greenglovess = localStorage.getItem("greengloves");
    blackglovess = localStorage.getItem("blackgloves");
    whiteglovess = localStorage.getItem("whitegloves");
    redglovess = localStorage.getItem("redgloves");
    
    
    function refresh(){
        document.getElementById("recipt").innerHTML =
            "Green Gloves: " + greenglovess +
            "Black Gloves: " + blackglovess +
            "White Gloves: " + whiteglovess +
            "Red Gloves: " + redglovess;
    }
</script>
</html>

How can I make it so that the gloves will be displayed on separate lines?

The Important Stuff:

<script>
    greenglovess = localStorage.getItem("greengloves");
    blackglovess = localStorage.getItem("blackgloves");
    whiteglovess = localStorage.getItem("whitegloves");
    redglovess = localStorage.getItem("redgloves");


    function refresh(){
        document.getElementById("recipt").innerHTML =
            "Green Gloves: " + greenglovess +
            "Black Gloves: " + blackglovess +
            "White Gloves: " + whiteglovess +
            "Red Gloves: " + redglovess;
    }
</script>
1
  • 1
    Quickest solution would be to append a <br>. "Green Gloves: " + greenglovess + "<br>" Commented May 19, 2021 at 4:11

2 Answers 2

2

You can add <br/> tag to add a newline in HTML

<!doctype html>
<html>

<head>
  <meta charset="utf-8">
  <title>Untitled Document</title>
</head>

<body>
  <p>Review Purchases</p>
  <p id="recipt"></p>
  <button onClick="refresh()" type="button">Refresh</button>
  <p><a href="Payment.html">PAY NOW</a></p>

</body>
<script>
  greenglovess = localStorage.getItem("greengloves");
  blackglovess = localStorage.getItem("blackgloves");
  whiteglovess = localStorage.getItem("whitegloves");
  redglovess = localStorage.getItem("redgloves");


  function refresh() {
    document.getElementById("recipt").innerHTML =
      "Green Gloves: " + greenglovess + "<br/>" +
      "Black Gloves: " + blackglovess + "<br/>" +
      "White Gloves: " + whiteglovess + "<br/>" +
      "Red Gloves: " + redglovess;
  }
</script>

</html>

Sign up to request clarification or add additional context in comments.

Comments

2

Use Template Literals.

See Multiline Strings:

Any newline characters inserted in the source are part of the template literal.

console.log(`string text line 1
string text line 2`);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.