on Change of dropdown list showld call the php function

前端 未结 2 1124
既然无缘
既然无缘 2020-12-10 10:05

On change of the dropdown list, A php function should called.

Inside the PHP function I will do some calculation. Later I need to set the value of a text box or else

相关标签:
2条回答
  • 2020-12-10 10:30

    You can't call a php function from js or html, but you can do that by ajax call to a php function where you can perform your calculation and then return the result value to js, so then you can do by js to html...

    Update:

    <select name="employee" id="employee" onchange="getIPL(this.value);">
       <option value="">Select Employee</option>
    </select>    
    
    function getIPL(id)
        {
                $.ajax({
                           type: "GET",
                           url: "EmpLeave.php",
                           data: "emp_Id =" + id,
                           success: function(result){
                             $("#somewhere").html(result);
                           }
                         });
        };
    
    
     // Empleave.php file....
      if(isset($_GET['emp_Id'])){
         GetTotalPL($_GET['emp_Id']);
     }
    
     function GetTotalPL($id){
      // do your calculation...
    }
    
    0 讨论(0)
  • 2020-12-10 10:39

    Insert your function in a php file to excute , then you could call php file with ajax ( i suggest u use jQuery )

    ///////////////////////// foo.php
    
    <?php
    
    Function foo (){
    
    // Your process
    
    }
    
    foo();
    
    ?>
    
    ///////////////////// text.html
    
    <select name="test" id="test" >
    <option>.....</option>
    .
    .
    .
    .
    </select>
    <script type='text/javascript' src='http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js'></script>
    <script type="text/javascript">
    $('#test').change(function(){
    $.ajax({
        type: "GET",
            url: "foo.php",
            success:function(){
            // Your function after execute foo.php
    
            }
                })
    
    })
    </script>
    
    0 讨论(0)
提交回复
热议问题