-3
<input id="total" />
<p></p>

I have html code that has a blank <p>, but once you add something into an input, the javascript is adding it to the <p> tag. I am wondering how to alert if the new value of <p> is over 5000.

I have:

if(document.getElementById("total").value > 5000){
    alert("to high");
}

but that seems to not affect the new value of the paragraph, how to I make is so the alert will show if the new value of the paragraph is over 5000?

Matthew
  • 83
  • 6
  • 2
    How does a p tag have a value? Why is this logic not in the code that is doing the sum not doing the check? – epascarello Mar 04 '19 at 17:56
  • 2
    Paragraphs don't have a `value` property. Only inputs do. You want the `innerText` or `innerHTML` parsed as a number – Turnip Mar 04 '19 at 17:58

1 Answers1

0

As the comments suggest, <p> elements don't have a value property. What you're looking for is innerHTML:

if(document.getElementById("total").innerHTML.length > 5000) {
    alert("too high");
}
vich
  • 11,836
  • 13
  • 49
  • 66
  • yes thank you, but now that the

    has changed to whatever an user input is, how to i alert if the user input is greater than 5000?

    – Matthew Mar 04 '19 at 18:05
  • the user has to put in a number, but if the number that he or she put in is over 5000, i want to show the alert – Matthew Mar 04 '19 at 18:11