douyou8047 2014-02-05 11:14
浏览 24

如何通过在没有提交按钮的情况下在另一个文本框中输入他的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

  • 写回答

3条回答 默认 最新

  • dongzhui9936 2014-02-05 11:22
    关注

    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);
    });
    
    评论

报告相同问题?