Variable help HTML

Discussion in 'HTML & Website Design' started by mattonfire, Oct 1, 2016.

  1. #1
    Hi! I'm not completely fluent in HTML, JS and CSS but I know bits and bobs.
    This and a couple of JS files will create a working slider as shown below.

    [​IMG]

    It's default number is "50" as shown in the value, I was wondering if I could use the slider as a variable. So the user slides it and chooses a number which is set into a variable. Then the variable I could use in HTML.


    <form>
    <label for="slider-1">Slider:</label>
    <input type="range" name="slider-1" id="slider-1" min="0" max="100" value="50">
    </form>
     
    mattonfire, Oct 1, 2016 IP
  2. mmerlinn

    mmerlinn Prominent Member

    Messages:
    3,197
    Likes Received:
    819
    Best Answers:
    7
    Trophy Points:
    320
    #2
    Look up the specs for the 'input' HTML form tag. There you will find that you can set the value as you please.
     
    mmerlinn, Oct 1, 2016 IP
  3. qwikad.com

    qwikad.com Illustrious Member Affiliate Manager

    Messages:
    7,326
    Likes Received:
    1,706
    Best Answers:
    31
    Trophy Points:
    475
    #3
    qwikad.com, Oct 3, 2016 IP
  4. ItsBrad

    ItsBrad Member

    Messages:
    12
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    36
    #4
    <form>
    <label for="slider-1">Slider:</label>
    <input type="range" name="slider-1" id="slider-1" min="0" max="100" value="50" onchange="updateVariable(this);">
    </form>
    
    <script type="text/javascript">
    var value = 0;
    function updateVariable(sender) {
        value = sender.value;
        console.log(value);
    }
    </script>
    Code (markup):
     
    ItsBrad, Oct 3, 2016 IP