user3400389
user3400389

Reputation: 367

Detect change in an input field when selecting value from a box

I want to detect a change in the input field when i select a value from the box like in the picture below.

<code>Selecting value from a box</code>

html:

<input type="text" class="AgeChangeInput" id="range"/>

js:(not working)

<script>
$(document).ready(function()
{
    alert("Hello");
    $("#range").bind('input', function()
    {
        alert("done");
    });
});
</script>

I also tried live on functions but they didn;t work too.

Upvotes: 0

Views: 171

Answers (2)

Alwin Kesler
Alwin Kesler

Reputation: 1520

Your date selection box should fire a change event, then you only need to capture it:

$(function () {
    $('#range').change(function () {
        ...
    });
});

If the selection box doesn't fire the event, you'll need to trick the dom. Something like:

$(document).ready(function () {
    // Asuming your selection box opens on input click
    $('#range').click(function () {
        $('.special-box-class').click(fireRangeEvent);
    });

    // Now the firing function
    function fireRangeEvent() {
        ...
    }
});

Hope it works

Upvotes: 3

Oyeme
Oyeme

Reputation: 11235

Try to use this code

changeDate - This event is fired when the date is changed.

 $('#range').datepicker().on('changeDate', function(ev) {
      //example of condition
      if (ev.date.valueOf() > checkout.date.valueOf()) {
       //make action here
        alert('Here');
      }
});

Upvotes: 2

Related Questions