php - How to disable a select option populated by database in javascript based on time range -
i working on project in values fetched database in select options. consider if options consist of 5 options aa,bb,cc,dd,ee
. problem want disable options aa
, dd
(or such other combination or individual option) after clock hits 11.30 on thursday , again enable on 11.30 on sunday.
<form id="main-order-form" name="order-form" method="post" action="" role="form"> <div class="row"> <div class="col-md-8"> <div class="row"> <div class="col-md-4"> <div class="form-group"> <label for="offercode" style="color:#fff"> offer code:</label> <select id="offercode" name="choose_code" class="form-control" tabindex="1" style="width:100%" required> <option value="">choose one:</option> <?php $query = "select id,code offercode"; $result = mysqli_query($conn, $query); while ($rows = mysqli_fetch_assoc($result)) { $code_id = $rows['id']; $code_name = $rows['code']; echo"<option value='$code_id'>$code_name</option>"; } ?> </select> </div> </div> <div class="col-md-4"> <div class="form-group"> <label for="foodtype" style="color:#fff"> veg / non-veg :</label> <select id="foodtype" name="foodtype" class="form- control" tabindex="2" style="width:100%" required> <option value="" selected="">choose one: </option> <option value="veg">veg</option> <option value="non-veg">non-veg</option> </select> </div> </div> <div class="col-md-4"> <div class="form-group"> <label for="quantity" style="color:#fff"> quantity :</label> <div class="input-group"> <span class="input-group-btn"> <button type="button" class="btn btn-default btn-number" disabled="disabled" data-type="minus" data-field="quantity"> <span class="glyphicon glyphicon-minus"></span> </button> </span> <input type="text" name="quantity" class="form-control input-number" tabindex="3" value="1" min="1" max="20" > <span class="input-group-btn"> <button type="button" class="btn btn-default btn-number" data- type="plus" data-field="quantity"> <span class="glyphicon glyphicon-plus"></span> </button> </span> </div> </div> </div> </div> </div> <div class="col-md-4"> <label for="submit-order" style="color:#fff"> submit order :</label> <input type="submit" name="submit-order" style="background-color:#c70039;color:#000" id="" tabindex="4" class="form- control btn btn-login" value="submit"> </div> </div> </form> <script type="text/javascript"> function timer () { time = new date(); var hh = time.gethours(); var mm = time.getminutes(); var dd = time.getday(); if (hh > "11" && mm == "30" && dd == "0,1,2,3,4") { // disable "offercode" select options (not specified // option) sunday 11.30 thursday 11.30 } else { // else keep enable } } </script>
you add custom data- attribute identify relevant option elements (e.g. queryselector) , set disabled attribute each option.
element.disabled=true;
edit:
to disable specified offercodes here 1 approach:
var select = document.getelementbyid('offercode'); var arrayofcodestodisable = ['aa', 'bb']; disableoptions(select, arrayofcodestodisable) function disableoptions(select, arrayofcodestodisable) { (var = 0; < select.options.length; i++) { if (arrayofcodestodisable.indexof(select.options[i].text) > -1) { select.options[i].disabled = true; } } }
in array "arrayofcodestodisable" define relevant offercodes. options of selectbox checked innerhtml (text) , disabled if contain text of array.
Comments
Post a Comment