Prompt the way you can use to prevent a button from being pressed if the option is always selected (by default) in the select option 'Select employee'. I found the simplest disabled = "disabled" on the Internet, but it doesn’t really fit me.

<form method="POST" name="apple" id="apple" action="index.php" target="_blank"> <br> <br> <br> <center> <select name="user" id="user"> <option >Выбрать сотрудника</option> <? foreach($row as $k=>$val){ ?> <option value="<?=$val[myid]?>"><?=$val[mname]?></option> <?}?> </select> <input type="submit" value="Перейти"/> </center> </form> 
  • What do you need to do? - Mihanik71
  • @ Mihanik71, make the Go button inactive when the Select employee item is selected. - Eliot

4 answers 4

 $('select[name=user]').change(function() { if ($("#user :selected").val() == 'Выбрать сотрудника') { $('input[type="submit"]').attr('disabled', 'disabled'); } else { $('input[type="submit"]').removeAttr('disabled'); } }); 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <form method="POST" name="apple" id="apple" action="index.php" target="_blank"> <br> <br> <br> <center> <select name="user" id="user"> <option>Выбрать сотрудника</option> <option value="574">adwdawdawdaw</option> <option value="574">dawdawdaw</option> <option value="574">adwdawda1232313wdaw</option> <option value="574">adwda12312312wdawdaw</option> </select> <input type="submit" value="Перейти" disabled/> </center> </form> 

    Option 2 :)

     <form method="POST" name="apple" id="apple" action="index.php" target="_blank"> <br> <br> <br> <center> <select name="user" id="user"> <option selected disabled>Выбрать сотрудника</option> <? foreach($row as $k=>$val){ ?> <option value="<?=$val[myid]?>"><?=$val[mname]?></option> <?}?> </select> <input type="submit" value="Перейти" disabled/> </center> 

    Js

     $('#user').on('change', function() { $('#apple input[type=submit]').prop('disabled', false); }); 

    Naturally need to connect jQuery

    Demo https://jsfiddle.net/Reset5/0jaorqo8/3/

      You can not deactivate the button, but use the required attribute.
      Then when you try to submit the form, validation will work:

      Select one of the list items.

       <form method="POST"> <select name="user" id="user" required> <option value="">Выбрать сотрудника</option> <option value="1">Сотрудник 1</option> <option value="2">Сотрудник 2</option> <option value="3">Сотрудник 3</option> <option value="4">Сотрудник 4</option> </select> <input type="submit" value="Перейти"/> </form> 

      Feeddle

         <select class="form-control" name="select" id="select" onchange="disable_btn();"> <option value="0">Выбрать сотрудника</option> .... </select> <input name="input-name" type="submit" value="Перейти"/> function disable_btn(){ if($('select[name=\'select\'] option:selected').val() == 0){ $('input[name=\'input-id\']').attr("disabled","disabled"); }else{ $('input[name=\'input-id\']').removeAttr("disabled"); } } 

        And also check the state of the select when the page loads, if some option is returned

         $('document').ready(function(){ disable_btn(); });