Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <h2>Single Read</h2> <p>The problem is that you're only reading the value once (at startup), instead of reading it every time the event occurs:</p> <pre><code>// this stores the value at startup (which is why you're always getting 1) var rangeInput = document.getElementById("rangeinput").value; </code></pre> <p>You should be reading the value in the handler instead:</p> <pre><code>function testtest(e) { // read the value from the slider: var value = document.getElementById("rangeinput").value; // now compare: if (value &gt; 0 &amp;&amp; value &lt; 5) { alert("First"); } else { alert("Second"); } } </code></pre> <p>Or to rewrite your code:</p> <pre><code>var rangeInput = document.getElementById("rangeinput"); var buttonInput = document.getElementById("btn"); if (buttonInput.addEventListener) { buttonInput.addEventListener("click", testtest, false); } else if (buttonInput.attachEvent) { buttonInput.attachEvent('onclick', testtest); } function testtest(e) { var value = rangeInput.value; if (value &gt; 0 &amp;&amp; value &lt; 5) { alert("First"); } else { alert("Second"); } } </code></pre> <h2>Updating rangevalue</h2> <p>It also looks like you want to update the output element with the value of the range. What you're currently doing is referring to the element by id:</p> <pre><code>onchange="rangevalue.value=value" </code></pre> <p>However, as far as I know, this isn't standard behavior; you can't refer to elements by their id alone; you have to retrieve the element and then set the value via the DOM.</p> <p>Might I suggest that you add a change listener via javascript:</p> <pre><code>rangeInput.addEventListener("change", function() { document.getElementById("rangevalue").textContent = rangeInput.value; }, false); </code></pre> <p>Of course, you'll have to update the code to use <code>addEventListener</code> or <code>attachEvent</code> depending on the browsers that you want to support; this is where <a href="http://jquery.com/" rel="noreferrer">JQuery</a> really becomes helpful.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload