Anjanesh Lekshminarayanan


oninput for range

Anjanesh Lekshminarayanan's photo
Anjanesh Lekshminarayanan
·May 11, 2021·

1 min read

Subscribe to my newsletter and never miss my upcoming articles

We often use onclick and onchange but here's a scenario where oninput is used to trigger a change in the range value.

<!DOCTYPE html>
<html lang="en">
<meta charset="utf-8" />
<title>oninput range</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="" integrity="sha384-B0vP5xmATw1+K9KRQjQERJvTumQW0nPEzvF6L/Z6nronJ3oUOFUFpCjEUQouq2+l" crossorigin="anonymous">
changeAge = (e) =>
    document.getElementById('span_age').innerHTML = 
    document.getElementById('span_age_center').innerHTML =;
<div class="container mt-5">
  <div class="form-group row">
    <label for="age" class="col-sm-2 col-form-label">Age (<span id="span_age">10</span>)</label>
    <div class="col-sm-10 d-flex">
        <div style="width:20px">5</div>
        <input type="range" class="form-control-range" id="age" name="age" min="5" max="18" value="10" oninput="changeAge(event)" style="margin-top:-10px;" />
        <div class="text-center" style="width:30px">18</div>
    <div class="col-sm-12 text-center">
        <span id="span_age_center">10</span>


Share this