2021年4月4日星期日

Changing the value of textbox when Selecting a value from dropdownlist

i'm currently developing an Employee Management System, and I Want to change the value of salary when changing the value of Drop Down List, So Here is my Table table_sg_step, this is my code for Index.php

  1. Drop Down List for Salary

    Salary Grade
                                                 <?php                                                     $query = "SELECT salary_grade FROM salarygrade_step";                                                  $query_run = mysqli_query($connection, $query);                                               ?>                                               <?php                                                   while($row = mysqli_fetch_assoc($query_run))                                                  {                                                      $sg = $row['salary_grade'];                                                      echo "<option value = '$sg'>                                                               $sg                                                           </option>";                                                  }                                                        ?>                                               </select>                                               <div class="invalid-feedback">                                                       Please provide a valid Salary Grade                                                   </div>                                            </div>  

2. Drop Down List for Step

 <div class="form-group col-md-2">                                                  <label><strong> Step </strong></label>                                                      <select class="custom-select" id="step" name = "step">                                                          <option value = "Step_1">Step 1</option>                                                          <option value = "Step_2">Step 2</option>                                                              <option value = "Step_3">Step 3</option>                                                              <option value = "Step_4">Step 4</option>                                                              <option value = "Step_5">Step 5</option>                                                          <option value = "Step_6">Step 6</option>                                                          <option value = "Step_7">Step 7</option>                                                           <option value = "Step_8">Step 8</option>                                                        </select>                                                  <div class="invalid-feedback">                                                          Please provide a valid Salary Grade                                                      </div>                                               </div>  

And for my Ajax 3. AJAX

jQuery(document).ready(function(){                                              $("step").on('change',function(){                                                  var step = $(this).val();                                                    if(step)                                                  {                                                      $.ajax({                                                          type    :   'GET',                                                          url     :   'regular_get_salary.php',                                                          data    :   {reg_step:step},                                                          success :   function(response){document.getElementById("salary").val = response;}                                                      });                                                    }                                              });                                          });  

This is my code for regular_get_salary.php

    <?php    session_start();    include_once('security.php');    $salarygrade       =   mysqli_real_escape_string($connection,$_POST['salarygrade']);  $step       =   mysqli_real_escape_string($connection,$_POST['step']);  $salary       =   mysqli_real_escape_string($connection,$_POST['salary']);    if(isset($_POST['reg_step'])){      $query = "SELECT * FROM salarygrade_step WHERE salary_grade = $salarygrade";      $query_run = mysqli_query($connection, $query);      while($row = mysqli_fetch_assoc($query_run)){          if($step == "Step_1"){              echo $row['Step_1'];          }          elseif($step == "Step_2"){              echo $row['Step_2'];          }          elseif($step == "Step_3"){              echo $row['Step_3'];          }          elseif($step == "Step_4"){              echo $row['Step_4'];          }          elseif($step == "Step_5"){              echo $row['Step_5'];          }          elseif($step == "Step_6"){              echo $row['Step_6'];          }          elseif($step == "Step_7"){              echo $row['Step_7'];          }          elseif($step == "Step_8"){              echo $row['Step_8'];          }               }  }  ?>  

So Basically once I Change the value of salary Grade and Step, it will automatically change the value of textbox(Salary) base on the given value (see the table_sg_step) .. Thank you

https://stackoverflow.com/questions/66947166/changing-the-value-of-textbox-when-selecting-a-value-from-dropdownlist April 05, 2021 at 09:01AM

没有评论:

发表评论