Search code examples
javascriptjqueryfunctiondomonchange

When using an event in JQUERY, I can't get it to make changes like I was able to with JavaScript Pure. change () method


I am a student, quite an amateur of javascript, at this moment I am introducing myself to Jquery, and I must pass some functions under this library, I cannot find a way to do this that I used to do so easily in pure JavaScript. The function that I had created in javascript, allowed that if an input of type range was moved, an input number, was altered at the same time, and the number changed.

Javascript Code

sliderV.onchange = function (){
    inputV.value = sliderV.value;
}

Jquery try

$("#inputRange").change(function(){
    $("#inputRange").val() = $("#aSolicitar").val();
});

Solution

  • I am giving you an generic answer because I can't get your range input and number input selectors exactly.

    $(document).on('change', 'input[type=range]', function(e){
       e.preventDefault();
       $('input[type=number]').val( $(this).val() );
    });
    

    You can change your selector as your convenience. E.g. input[type=range] to #inputRange

    $(document).on('change', 'input[type=range]', function(e){
                    e.preventDefault();
                    $('input[type=number]').val( $(this).val() );
                });
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
    
    <p>JQuery Range input change event</p>
    <input type="range" id="inputRange" value="50" />
    <br/>
    <input type="number" id="inputNumber" value="50" />