-3

this variable is undefined outside the function()
i want this variable work outside function() and I want this variable to change every time I choose the selected option
code :

<script type="text/javascript">
   var interval_day;
   $('#select_id').change(function(){
      interval_day = $('#select_id').val();
   });
   document.getElementById('etst').innerHTML = interval_day;
<script>

html code :

 <select id="select_id">
     <option value="1">One</option>
     <option value="2">Two</option>
 </select>

please help me for this..

Asep Nurjaman
  • 156
  • 11

2 Answers2

1

If You want Global Variable then Use Like Below:

<script type="text/javascript">
    var  interval_day; ///Define your Global Variable
 $('#select_id').change(function(){
     interval_day = $('#select_id').val(); ////Put Value in Global variable
      });

$(function() {
 $("#pickup").datepicker({
    dateFormat: 'yy-mm-dd',
     minDate: inverval_day
   });
});
<script>
Saifur Rahman
  • 144
  • 2
  • 14
0

no need to make it global var just get it direct from select value

<script type="text/javascript">
$(function() {
   $("#pickup").datepicker({
      dateFormat: 'yy-mm-dd',
      minDate: Number($('#select_id').val())
   });
});
<script>

I didn't use same value because it has to be number so you have to cast it to number Number($('#select_id').val()) to work with datepicker

Ahmed Yousif
  • 2,298
  • 1
  • 11
  • 17