如何通过在没有提交按钮的情况下在另一个文本框中输入他的Reg.ID来自动获取学生班级

I have created a form in php/html for student attendance now what I want is that when I enter student reg.id in "std_id" text box his class in which he is studying should be fetched from the table of database and appear it in "class" text box.

The name of the table is ("student_attendance") in the database. I don't know how to do this. So please help me doing it.

` Student Reg. ID:

      <td> Class: </td>
      <td> <input type="text" name="class"/> </td>
    </tr>

    <tr>
      <td> Section: </td>
      <td> <input type="text" name="section"/> </td>

      <td> Session: </td>
      <td> <input type="text" name="session"/> </td>
    </tr>

     <tr>
      <td> Date: </td>
      <td> <input type="date" name="date"/> </td>
    </tr>

    <tr>
      <td> Present Status: </td>
      <td> <input type="text" name="pstatus"/> </td>
    </tr>

  </table>

        <input type="submit" name="SAVE"/> //is used to save the form data in db

  </form>`

Thanks

Simply you need to do an ajax call to get data from backend. Ajax is a technology to perform requests from browser without refreshing the page. It does a request and gets response (usually returned in json format) based on which you decide in frond end what to do (maybe display your desired data from response somewhere).

Here is a tutorial on general ajax: http://www.w3schools.com/ajax/ Also it is nice to attach jQuery lib and use it's $.ajax() method with its success and fail handlers: http://api.jquery.com/jquery.ajax/

You should have a php file where you will get the class by student id. Something like this:

<?php
    $id = $_GET('std_id');
    //connect to mysql
    //select * from student_attendance where std_id = $id;
    //get result
    echo array('class'=>$result['class']);
?>

And in frontend on reg.id blur or change:

$.ajax({
  url: "test.php",
  type: 'POST'
}).done(function(response) {
  $('input[name=class]').val(response.class);
});

You can use following code :

$(document).ready(function (){

$("input[name=std_id]").blur(function (){ var reg_id=$("input[name=std_id']").val(); // now make ajax call for fething class data from table : $.ajax({ type:'get', url: 'test.php', data:{regid:reg_id} }).done(function(result){ //store response in class textbox: $("input[name=class']").val(result); }); }); Dont forget add jquery and ajax plugin.

You can use OnChange() attribute in javascript to trigger your database from background. Or you can use Ajax.