1

I am using a library called pickadate/pickatime. http://amsul.ca/pickadate.js/time/

here is the code:

<select id="day" onchange="myFunction()">
    <option value="[7,30]">Day 1</option>
    <option value="[8,00]">Day 2</option>
    <option value="[10,20]">Day 3</option>
</select>
<input type="text" id="time">

<script>
var value = document.getElementById('day').value;
function myFunction() {
    $('#time').pickatime( {
        min: value // minimum time
    });
}
</script>

let me explain what the code does.

every time the select changes, the onchange myFunction() should fire. it does on the first time. that's the problem. If I first select day 2, it will insert the min value [8,00] in the javascript function.

if i DO NOT refresh the page and select day 1 or day 3 after i have already selected something, it will not update the min value. how can i fix this?

EDIT: The problem: i'm initializing $('#time').pickatime... the first time. how can i reinitialize it or refresh it?

Jason Bale
  • 363
  • 2
  • 7
  • 14

2 Answers2

0
$('#time').pickatime();
var element = document.getElementById('day');
function myFunction() {
    $('#time').pickatime( {
        min: element.value // minimum time
    });
}
gaheinrichs
  • 565
  • 5
  • 13
0

You need to clear time input value. Try like below;

 $('input[type="time"]').val(null);
eisbach
  • 417
  • 3
  • 7