1

I have a value being updated by an HTML range slider through javascript. I need to grab this number as a variable in javascript. How can I achieve this? Here's what I have so far.

<form class="daysAR"
<label for="days">Days</label><br />
<input type="range" min="0" max="31" value="15" id="days" step="1" oninput="accountsRecievableSlider(value)">
<output for="days" id="daysInAR">15</output>
</form>

Javascript

function accountsRecievableSlider(AR) {
document.querySelector('#daysInAR').value = AR;
}

This is how I'm unsuccessfully trying to get the variable.

var selectday = document.querySelector('#daysInAR').value
document.write(selectday);

Thanks.

1
  • 1
    Could please post a js fiddle demo Commented Sep 16, 2015 at 19:51

2 Answers 2

2

You haven't closed the form tag. try pasting this is an empty HTML:

<form class="daysAR">
    <label for="days">Days</label><br />
    <input type="range" min="0" max="31" value="15" id="days" step="1" oninput="accountsRecievableSlider(value)">
    <output for="days" id="daysInAR">15</output>
</form>


<script type="text/javascript">
function accountsRecievableSlider(AR) {
    document.querySelector('#daysInAR').value = AR;
    var selectday = document.querySelector('#daysInAR').value
    console.log(selectday);
}
</script>

Worked for me

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

2 Comments

I'm sorry, what did I do wrong? Your example works for me, but the only difference I see is that you wrote it to the console. Regardless thanks.
I also closed the form tag and put your code inside the function.
0

Can you check on your browser console?

On this fiddle : jsfiddle you can see an example.

window.accountsRecievableSlider = function() {
  document.querySelector('#daysInAR').value = document.querySelector('#days').value
}

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.