How to load JavaScript Data Only when selecting a value from a Listboxt?

0

I need to load the data that is inside a Javascript, but only when selecting the value of a listboxt, because if it is not this way, it will give me an error in the system because the data inside the javascript must be filtered by a parameter. I already have the Functions to filter them, however I do not know how to make the data inside the javascript do not load automatically when loading my page. I think this could be done with JSON, but I do not know why I do not know much about its use (I've only used it a bit for this university project) To pass the parameter I would use JQuery .change, but that's the least of it. Any information would be very helpful, thank you.

Data that I need to load when passing a parameter:

businessHours: [ // specify an array instea
{
    dow: [ 1], // Monday

    <?php foreach($monday as $row){?>
       start: '<?php  $inicio= "00:00"; $start1_ok = $row->hrs_ini;

    if (empty($start1_ok)) { echo $inicio;}
    else { echo $start1_ok;} ?>',  // empty evalua si el campo se encuentra vaio o si es cero
    end: '<?php echo $row->hrs_ter ;?>' 
    <?php }?>
},
{
    dow: [2], // Tuesday
    <?php foreach($tuesday as $row1){?>
       start: '<?php  $inicio= "00:00"; $start1_ok = $row1->hrs_ini;

    if (empty($start1_ok)) { echo $inicio;}
    else { echo $start1_ok;} ?>',   // 10am
    end: '<?php echo $row1->hrs_ter ;?>' // 4pm
    <?php }?>
},
{
    dow: [3], //  Wednesday
    <?php foreach($wednesday as $row2){?>
       start: '<?php  $inicio= "00:00"; $start1_ok = $row2->hrs_ini;

    if (empty($start1_ok)) { echo $inicio;}
    else { echo $start1_ok;} ?>',  // 10am
    end: '<?php echo $row2->hrs_ter ;?>' // 4pm
    <?php }?>
},
{
    dow: [4], // Thursday
    <?php foreach($thursday as $row3){?>
       start: '<?php  $inicio= "00:00"; $start1_ok = $row3->hrs_ini;

    if (empty($start1_ok)) { echo $inicio;}
    else { echo $start1_ok;} ?>',  // 10am
    end: '<?php echo $row3->hrs_ter ;?>' // 4pm
    <?php }?>
},
{
    dow: [5], // Friday
    <?php foreach($friday as $row4){?>
    start: '<?php  $inicio= "00:00"; $start1_ok = $row4->hrs_ini;

    if (empty($start1_ok)) { echo $inicio;}
    else { echo $start1_ok;} ?>', 
    end: '<?php echo $row4->hrs_ter ;?>'// 4pm

    <?php }?>
},
{
    dow: [6], // Saturday

    <?php foreach($saturday as $row5){?>

    start: '<?php  $inicio= "00:00"; $start_ok = $row5->hrs_ini;

    if (empty($start_ok)) { echo $inicio;}
    else { echo $start_ok;} ?>', 
    end: '<?php echo $row5->hrs_ter ;?>'
     <?php }?>
}
];
    
asked by CristianOx21 16.10.2017 в 17:03
source

1 answer

0

Well, I'll give you a solution to your problem Try this,

function select(){
  var numeros = $('#numeros').val();
  
  alert(numeros);
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<select name="numeros" id="numeros" onchange='select()'>
  <option value="Select">Select</option>
  <option value="01">01</option>
  <option value="02">02</option>
  <option value="03">03</option>
  <option value="04">04</option>
</select>

I hope it works for you try to run the code before using it

    
answered by 16.10.2017 в 17:14