handle div tag visibility in php using javascript after submitting button -


in code when select option 3 value business div visible(for option 1 , 2 value hidden) after submitting button business div not visible.so, please me solve it.

html code

    <form method="get" action="<?php echo $_server['php_self']; ?>"  <table width="30%" border="1px solid white"><tr border="1px solid white"> <td><select id='purpose' name="purpose" style="color:black">              <option value="1" <?php echo $d1 ?>>current day</option>             <option value="2" <?php echo $d2 ?>>current month</option>             <option value="3" <?php echo $d3 ?>>custom</option>     </select></td></tr></table></br>     <div style='display:none;' id='business'>      <table width="50%"><tr> <td width="50%">start date<input style="color:black;background-color:white;" type="text" id="basic_example_1" name="stdt" placeholder="yyyy-mm-dd hh:mm"/>               </td>     <td >end date<input style="color:black;background-color:white;" type="text" id="basic_example_3" name="spdt" placeholder="yyyy-mm-dd hh:mm"/>              </td></tr></table>     </div>      <button type="submit" name="table"  value="reg" class="btn btn-success" style="width:20%;height:35px;margin-top:5px" >submit</button>          </form> 

javascript code

<script>  $(document).ready(function(){        $('#purpose').on('change', function() {       if ( this.value == '3')       {         $("#business").show();         }       else if(this.value == '2')       {         $("#business").hide();       }       else if(this.value == '1')       {                   $("#business").hide();        }     });   });      </script>     

try code.

 <?php         $dispdiv ="display:none;";          if(isset($_get['purpose']) && ($_get['purpose'] == 3)){             $dispdiv ="display:block;";                  }      ?>          <form method="get" action="<?php echo $_server['php_self']; ?>" <table width="30%" border="1px solid white">             <tr border="1px solid white">                 <td>                     <select id='purpose' name="purpose" style="color:black">                          <option value="1" <?php echo $d1 ?>>current day</option>                         <option value="2" <?php echo $d2 ?>>current month</option>                         <option value="3" <?php echo $d3 ?>>custom</option>                     </select>                 </td>             </tr>             </table>             </br>              <div style='<?php echo $dispdiv;?>' id='business'>                  <table width="50%">                     <tr>                         <td width="50%">start date                             <input style="color:black;background-color:white;" type="text" id="basic_example_1" name="stdt" placeholder="yyyy-mm-dd hh:mm" />                          </td>                         <td>end date                             <input style="color:black;background-color:white;" type="text" id="basic_example_3" name="spdt" placeholder="yyyy-mm-dd hh:mm" />                          </td>                     </tr>                 </table>             </div>              <button type="submit" name="table" value="reg" class="btn btn-success" style="width:20%;height:35px;margin-top:5px">submit</button>          </form>         <script>             jquery(document).ready(function($) {                  $('#purpose').on('change', function() {                     if (this.value == '3') {                         $("#business").show();                      } else if (this.value == '2') {                         $("#business").hide();                     } else if (this.value == '1') {                         $("#business").hide();                      }                 });              });         </script> 

Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -