I am encountering some difficulties...
I have an <input>
field. Depending on the input, one of the various <div>
elements should be displayed. For now, it's just a text (e.g. "Your plan contains less than 1500 kcal!"), but later, the div elements will be blocks with images, buttons, etc.
I have come across some ideas using jQuery, but since I am new to it, I find it hard to understand. So, I tried using the if-function and changing the style from none to block.
What am I missing? The div doesn't seem to appear... As a beginner in JavaScript, any tips you have, please explain it as though to a complete novice :)
Thank you everyone!
HTML
<body style="background-color:#000000">
<form>
<p>
<label for=bedarf> Mein Bedarf </label>
<input type="bedarf" name="bedarf" id="bedarf" placeholder="2345">
<button class="button1" type="button" id="berechnen" onclick="planholen()" > Plan anzeigen </button><br><br><br>
</form>
<div class="anzeige" id="erster" ><p>Dein Plan enthält weniger als 1500 kcal!</p></div>
...
<div class="anzeige" id="dreizehnter" ><p>Dein Plan enthält weniger als 3900 kcal!</p></div>
</body>
CSS
<style>
label {
width: 100px;
display: inline-block;
font-family: Arial;
color: #ffffff;
}
input {
width: 120px;
height: 25px;
text-align: center;
font-family: Arial;
font-size: 14px
}
...
JS
<script>
function planholen() {
var a = document.getElementById("erster");
var b = document.getElementById("zweiter");
...
var m = document.getElementById("dreizehnter");
var val = parseInt(document.getElementById("bedarf"));
if (val < 1500) { a.style.display = "block"; } else
...
if (val < 3900) { m.style.display = "block"; }
</script>