Monday, November 18, 2024
Google search engine
HomeLanguagesJavascriptscript.aculo.us Sliders setValue option

script.aculo.us Sliders setValue option

The script.aculo.us library is a cross-browser library that aims at improving the user interface of a website. The Slider controls are thin tracks that allow the user to input values. It is done by defining a range of values that can be selected by the user by dragging the handle to the appropriate value.

The Sliders setValue function is used to update the value of the slider to the given value. It will move the handle of the slider to the appropriate position of the slider track. The onChange() callback function is invoked whenever this method is used and can be used to track the change in value.

Syntax:

setValue( value, handleIndex )

Parameters: This function has two parameters as mentioned above and described below:

  • value: It is a number that will be used to update the value of the slider.
  • handleIndex: It is used to define the index of the slider to be updated when using multiple sliders. It is an optional parameter. When this value is not passed, then the last used slider is updated.

Example:




<!DOCTYPE html>
<html>
<head>
  <!-- Include the required scripts -->
  <script type="text/javascript"
          src="prototype.js">
  </script>
  <script type="text/javascript" 
          src="scriptaculous.js?load = slider">
  </script>
  
  <!-- Style the Sliders so that they
  are properly visible -->
  <style type="text/css">
    .track {
      width: 250px;
      background-color: gray;
      height: 5px;
      position: relative;
    }
  
    .track .handle {
      width: 20px;
      height: 10px;
      background-color: green;
      cursor: move;
      position: absolute;
      top: -2px;
    }
  
    .pad {
      padding: 25px;
    }
  </style>
</head>
<body>
  <p>
  <h1 style="color: green;">
    neveropen
  </h1>
  <h2>Sliders setValue</h2>
  <p>
    The value of the slider can be set
    by using the setValue() method 
    as shown below.
  </p>
  
  <input type="text" id="val">
  <button onclick="setVal()">
    Set Value
  </button>
  
  <div class="pad">
    <div id="track-hor" class="track">
      <div id="handle-hor" class="handle">
      </div>
    </div>
  </div>
  <p>Current Slider Value: 
    <span id="out">0</span>
  </p>
  
  <script type="text/javascript">
  
    // Initialize the slider
    let slider = new Control.Slider(
      'handle-hor',
      'track-hor', {
        
      // Define the range
      range: $R(1, 100),
  
      onChange: function (v) {
        document.querySelector("#out")
                .textContent = v;
      }
    });
  
    function setVal() {
  
      // Get the value form the input box
      let val = 
          document.querySelector("#val").value;
  
      // Set the value of the slider
      // to the given value
      slider.setValue(val);
    }
  </script>
</body>
</html>


Output:

Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!

Dominic Rubhabha-Wardslaus
Dominic Rubhabha-Wardslaushttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Recent Comments