douci4026 2014-05-14 10:29
浏览 60

使用AJAX根据选择填充表单域

So I'm having trouble figuring out how to get this done. I'll explain briefly what happens and what needs to happen. First of all a dokter can add patiënts into a database ( currently only firstname, lastname, age, ... ). this is already working but now I want the dokter to be able to search the database based on the "profile" fields of a certain patiënt in order to look for similar patients. So what I have is a dropdown that shows the patients this dokter has added ( mypatients) and whenever he selects one of those patients from the dropdown menu the fields get updated based on that selection. This is the code I have right now:

-- This is the php I run to add users in the dropdown field (the MyPatients- functions selects all the patients where the username is the same as the dokters username that is currently logged in ):

<?php

session_start();
include_once("classes/Db.class.php");
include_once("classes/Patient.class.php");


if(!isset($_SESSION['username']))
{
   header("Location: login.php");
}

$patient = new Patient();
$patient->Dokter = $_SESSION['username'];

$results = $patient->MyPatients();

?>

-- This is the search form ( includesearch.php )

<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" class="form-horizontal" role="form">

<div class="form-group">
  <label class="col-lg-2 control-label">Mijn Patiënt</label>
  <div class="col-lg-2">
    <select name="selectedpatient" class="form-control">
      <option value"" disable selected>&nbsp;</option>
      \<?php 
      while($r = $results->fetch_assoc()){
        echo "<option>". $r["firstname"] . " " . $r["lastname"] . "</option>";
      }
      ?>
    </select>
  </div>
</div>


<!-- SCRIPT FOR DATEPICKER -->

<div class="form-group">
  <label class="col-lg-2 control-label">Leeftijd</label>
  <div class="col-lg-5">
    <input id="age" name="age" type="text" class="form-control" placeholder="age">
</div>

</div>

 <div class="form-group">
  <label class="col-lg-2 control-label">Language</label>
  <div class="col-lg-5">
    <label class="checkbox-inline">
      <input type="checkbox" id="inlineCheckbox1" value="nl"> NL
    </label>
    <label class="checkbox-inline">
      <input type="checkbox" id="inlineCheckbox2" value="fr"> FR
    </label>
    <label class="checkbox-inline">
      <input type="checkbox" id="inlineCheckbox3" value="en"> EN
    </label>
  </div>
</div>

 <div class="form-group">
  <label class="col-lg-2 control-label">Profession</label>
  <div class="col-lg-2">
    <select name="profession" class="form-control">
      <option value"" disable selected>&nbsp;</option>
      <option value="jobless">Without a job</option>
      <option value="selfemployed">Selfemployed</option>
      <option value="student">Student</option>
    </select>
  </div>
</div>

</form>

I have tried using ajax with the document.getElementById, but so far without succes.

  • 写回答

1条回答 默认 最新

  • douchushao7799 2014-05-14 10:39
    关注
    1. you would need a php which returns patient details when patient id is posted
    2. than add onchange for your selectedpatient selectbox which uses ajax to post the patient id to this php you just created.
    3. the patient id could be added as value of the options in your selectbox.
    4. and lastly you'd need to add a success callback function for your ajax, which uses javascript to populate profile info to your html form
    评论

报告相同问题?

悬赏问题

  • ¥15 为什么apriori的运行时间会比fp growth的运行时间短呢
  • ¥15 帮我解决一下膳食平衡的线性规划模型的数据实例
  • ¥40 万年历缺少农历,需要和阳历同时显示
  • ¥250 雷电模拟器内存穿透、寻基址和特征码的教学
  • ¥200 比特币ord程序wallet_constructor.rs文件支持一次性铸造1000个代币,并将它们分配到40个UTXO上(每个UTXO上分配25个代币),并设置找零地址
  • ¥15 关于Java的学习问题
  • ¥15 如何使用chatgpt完成文本分类任务?
  • ¥15 已知速度v关于位置s的等式,怎么转化为已知位置求速度v的等式
  • ¥15 我有个餐饮系统,用wampserver把环境配置好了,但是后端的网页却进去,是为什么,能不能帮远程一下?
  • ¥15 R运行没有名称为"species"的插槽对于此对象类"SDMmodelCV"