Php 从下拉值更改文本框

Php 从下拉值更改文本框,php,mysql,ajax,Php,Mysql,Ajax,是否可以通过单击按钮向文本框添加文本 该页面包含三个下拉列表(类别、子类别、项目)。 首先,用户在下拉列表中选择一个类别。 在第二个下拉列表中,将显示该类别中的所有项目。 在第三个下拉列表中,将显示子类别中包含的所有项目。 示例:服务交付–服务台–帮助1 用户应该能够从最后一个下拉框中选择一个项目,按下按钮,该项目的所有属性(背景、资格、专业技能)都应该显示在下面的文本框中 我能够使用JavaScript创建连接的下拉列表。最后一个下拉列表中的项目也保存在“角色表”的“角色id”属性下 CREA

是否可以通过单击按钮向文本框添加文本

该页面包含三个下拉列表(类别、子类别、项目)。 首先,用户在下拉列表中选择一个类别。 在第二个下拉列表中,将显示该类别中的所有项目。 在第三个下拉列表中,将显示子类别中包含的所有项目。 示例:服务交付–服务台–帮助1

用户应该能够从最后一个下拉框中选择一个项目,按下按钮,该项目的所有属性(背景、资格、专业技能)都应该显示在下面的文本框中

我能够使用JavaScript创建连接的下拉列表。最后一个下拉列表中的项目也保存在“角色表”的“角色id”属性下

CREATE TABLE role (
  role_id INTEGER(5) UNSIGNED NOT NULL AUTO_INCREMENT,
  background VARCHAR(5000) NULL,
  tasks VARCHAR(5000) NULL,
  knowledge VARCHAR(5000) NULL,
  training VARCHAR(5000) NULL,
  professional VARCHAR(5000) NULL,
  qualifications VARCHAR(5000) NULL,
  PRIMARY KEY(role_id)
)
我使用MySQL作为数据库,PHP作为脚本操作,JavaScript作为下拉列表。看看Web上的示例,Ajax似乎是最合适的解决方案。 根据“role_id”,项目的属性需要添加到空文本框中

这是我到目前为止所做的代码。 任何例子或建议都将不胜感激

非常感谢

Role.html

   <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Role details - BCS UPDS Web application</title>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1251"/>
<link rel="stylesheet" type="text/css" href="pagestyle.css" />
<script type="text/javascript" src="role_selection.js"></script>

</head> 


<p>Logged in as Student</p>

<p id="pos_help"><a style="text-decoration: none"href="#">Help</a></p>
<p id="pos_logout"><a style="text-decoration: none" href="#">Log out</a></p>


<h3 id="pos_header">BCS UPDS Web application</h3>


<table border="0" cellpadding="0" cellspacing="0" id="pos_list"><tr><td>
 <ul id="button"> 
    <li><a href="personal.html">Personal details</a></li>
    <li><a href="role.html">Roles</a></li>
    <li><a href="job.html">Job description</a></li>
    <li><a href="#">Career Development Plan (CDP)</a></li>
    <li><a href="#">End Cycle Review</a></li>
    <li><a href="#">Help</a></li>
 </ul>
</td></tr></table>


<div class="box1">
<form action="role.php" method="post" id="role">

<table width="443" border="0">

<tr>
<td style="text-align: left;">Select Function Grouping</td>
<td style="text-align: left;">
<select name="function_grouping" id="function_grouping" onchange="setFunction();">
  <option value="Systems Development and Maintenance">Systems Development and Maintenance</option>
  <option value="Service Delivery">Service Delivery</option>
  <option value="Technical Advice and Consultancy">Technical Consultancy and Advice</option>
  <option value="Quality">Quality</option>
  <option value="Customer Relations">Customer Relations</option>
  <option value="Education and Training">Education and Training</option>
  <option value="Support and Administration">Support and Administration</option>
</select>
</td>
</tr><tr>
<td style="text-align: left;">Select Function</td>
<td style="text-align: left;">
<select name="role_level" id="role_level" onchange="setRoleLevel();">
  <option value="">Select Function Grouping</option>
</select>
</td>
</tr><tr>
<td style="text-align: left;">Select Role Level</td>
<td style="text-align: left;">
<select name="function2"  id="function2">
  <option value="function">Select Function Grouping</option>
</select>
</td>

</tr>
</table>

<input type="submit" name="Submit" value="Select role" id="selectrole"  /></p>

<br></br>

<fieldset id="fieldset">
<legend id="legend">Background</legend>
<p>
  <label for="background"></label>
  <textarea name="textarea" cols="71" rows="10" id="backgroundtext">
</textarea></p>
</fieldset>
<br></br>


<fieldset id="fieldset">
<legend id="legend">Tasks</legend>
<p>
   <label for="tasks"></label>
   <textarea name="textarea" cols="71" rows="10" id="taskstext">
</textarea></p>
</fieldset>
<br></br>


<fieldset id="fieldset">
<legend id="legend">Knowledge and Skills</legend>
<p>
   <label for="knowledge"></label>
   <textarea name="textarea" cols="71" rows="10" id="knowledgetext">
   </textarea></p>
</fieldset>
 <br>  </br>



<fieldset id="fieldset">
<legend id="legend">Training</legend>
<p>
   <label for="training"></label>
   <textarea name="textarea" cols="71" rows="10" id="trainingtext">
</textarea></p>
</fieldset>
<br></br>



<fieldset id="fieldset">
<legend id="legend">Professional Development Activities</legend>  
<p>
   <label for="professional"></label>
   <textarea name="textarea" cols="71" rows="10" id="professionaltext">
   </textarea></p>
 </fieldset>  
   <br></br>


<fieldset id="fieldset">
<legend id="legend">Qualifications</legend> 
<p>
   <label for="qual"></label>
   <textarea name="textarea" cols="71" rows="10" id="qualtext">

   </textarea></p>
</fieldset>
<br></br>

<p><input type="submit" name="Submit" value="Add role to job description" id="addjobdesc" /></p>

</form>
</div>
</body>
</html>

角色详细信息-BCS UPDS Web应用程序
以学生身份登录

BCS UPDS Web应用程序
选择函数分组 系统开发和维护 服务交付 技术咨询和咨询 品质 客户关系 教育和培训 支持和管理 选择函数 选择函数分组 选择角色级别 选择函数分组



背景



任务



知识和技能



训练



专业发展活动



资格



角色_selection.js

var function1 = new Array();

function1['Systems Development and Maintenance'] = new Array('Applications Support','Business Analysis','Data Analysis','Database Design', 'Documentation/Technical Authoring','Porting/Software Integration','Programming/Software Creation','Safety Engineering','Software Engineering','Systems Design','Systems Integration','Software Testing','Web Site Specialism');
function1['Service Delivery'] = new Array('Computer Operations','Database Administration','Hardware/Software Installation','Help Desk','Installation and Implementation','Network Administration and Support','Network Operations','Service Level Monitoring','User Support'); 
function1['Technical Advice and Consultancy'] = new Array('System Ergonomics Evaluation');
function1['Quality'] = new Array('Quality Standards');
function1['Customer Relations'] = new Array('Marketing','Sales Support'); 
function1['Education and Training'] = new Array('Education and Training Delivery');
function1['Support and Administration'] = new Array('Change Management','Configuration Management','Project Office','Security Administration');



var rolelevel = new Array();

rolelevel['Systems Development and Maintenance'] = new Array();
rolelevel['Systems Development and Maintenance']['Applications Support'] = new Array('ASUP1','ASUP2');
rolelevel['Systems Development and Maintenance']['Business Analysis'] = new Array('ANAL2');
rolelevel['Systems Development and Maintenance']['Data Analysis'] = new Array('DTAN1','DTAN2');
rolelevel['Systems Development and Maintenance']['Database Design'] = new Array('DBDS1','DBDS2');
rolelevel['Systems Development and Maintenance']['Documentation/Technical Authoring'] = new Array('DOCM1','DOCM2');
rolelevel['Systems Development and Maintenance']['Porting/Software Integration'] = new Array('PORT2'); 
rolelevel['Systems Development and Maintenance']['Programming/Software Creation'] = new Array('PROG1','PROG2');
rolelevel['Systems Development and Maintenance']['Safety Engineering'] = new Array('SFEN2');
rolelevel['Systems Development and Maintenance']['Software Engineering'] = new Array('SENG1','SENG2');
rolelevel['Systems Development and Maintenance']['Systems Design'] = new Array('DESN2');
rolelevel['Systems Development and Maintenance']['Systems Integration'] = new Array('SIST1','SIST2');
rolelevel['Systems Development and Maintenance']['Software Testing'] = new Array('TEST1','TEST2');
rolelevel['Systems Development and Maintenance']['Web Site Specialism'] = new Array('WBSP1','WBSP2');

rolelevel['Service Delivery'] = new Array();
rolelevel['Service Delivery']['Computer Operations'] = new Array('COPS0','COPS1');
rolelevel['Service Delivery']['Database Administration'] = new Array('DBDS1','DBDS2');
rolelevel['Service Delivery']['Hardware/Software Installation'] = new Array('HSIN1','HSIN2');
rolelevel['Service Delivery']['Help Desk'] = new Array('HELP0','HELP1','HELP2');
rolelevel['Service Delivery']['Installation and Implementation'] = new Array('INIM1','INIM2');
rolelevel['Service Delivery']['Network Administration and Support'] = new Array('NTAS2');
rolelevel['Service Delivery']['Network Operations'] = new Array('NTOP0','NTOP1','NTOP2');
rolelevel['Service Delivery']['Service Level Monitoring'] = new Array('SLMO2');
rolelevel['Service Delivery']['User Support'] = new Array('USUP1','USUP2');


rolelevel['Technical Advice and Consultancy'] = new Array();
rolelevel['Technical Advice and Consultancy']['System Ergonomics Evaluation'] = new Array('HCEV2');

rolelevel['Quality'] = new Array();
rolelevel['Quality']['Quality Standards'] = new Array('QUST1','QUST2');

rolelevel['Customer Relations'] = new Array();
rolelevel['Customer Relations']['Marketing'] = new Array('MKTG2');
rolelevel['Customer Relations']['Sales Support'] = new Array('SSUP1','SSUP2');

rolelevel['Education and Training'] = new Array();
rolelevel['Education and Training']['Education and Training Delivery'] = new Array('ETDL2');

rolelevel['Support and Administration'] = new Array();
rolelevel['Support and Administration']['Change Management'] = new Array('CHMG2');
rolelevel['Support and Administration']['Configuration Management'] = new Array('CFMG2');
rolelevel['Support and Administration']['Project Office'] = new Array('PROF2');
rolelevel['Support and Administration']['Security Administration'] = new Array('SCAD2');




function setFunction() {
  functiongSel = document.getElementById('function_grouping');
  rolelevelList = function1[functiongSel.value];
  changeSelect('role_level', rolelevelList, rolelevelList);
  setRoleLevel();
}

function setRoleLevel() {
  functiongSel = document.getElementById('function_grouping');
  functionSel = document.getElementById('role_level');
  functionList = rolelevel[functiongSel.value][functionSel.value];
  changeSelect('function2', functionList, functionList);
}

function changeSelect(fieldID, newOptions, newValues) {
  selectField = document.getElementById(fieldID);
  selectField.options.length = 0;
  for (i=0; i<newOptions.length; i++) {
    selectField.options[selectField.length] = new Option(newOptions[i], newValues[i]);
  }
}


function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }
  }
}

addLoadEvent(function() {
  setFunction();
});
var function1=新数组();
功能1[“系统开发和维护”]=新阵列(‘应用程序支持’、‘业务分析’、‘数据分析’、‘数据库设计’、‘文档/技术编写’、‘移植/软件集成’、‘编程/软件创建’、‘安全工程’、‘软件工程’、‘系统设计’、‘系统集成’、‘软件测试’、‘网站专业化’);
功能1[“服务交付”]=新阵列(“计算机操作”、“数据库管理”、“硬件/软件安装”、“帮助台”、“安装和实施”、“网络管理和支持”、“网络操作”、“服务级别监控”、“用户支持”);
功能1[“技术建议和咨询”]=新阵列(“系统工效学评估”);
function1['Quality']=新数组(“质量标准”);
功能1[“客户关系”]=新阵列(“营销”、“销售支持”);
功能1[“教育和培训”]=新阵列(“教育和培训交付”);
功能1[“支持和管理”]=新阵列(“变更管理”、“配置管理”、“项目办公室”、“安全管理”);
var rolelevel=新数组();
rolelevel['Systems Development and Maintenance']=新阵列();
rolelevel['Systems Development and Maintenance']['Applications Support']=新阵列('ASUP1','ASUP2');
rolelevel['Systems Development and Maintenance']['Business Analysis']=新阵列('ANAL2');
rolelevel['Systems Development and Maintenance']['Data Analysis']=新阵列('DTAN1','DTAN2');
rolelevel['Systems Development and Maintenance']['Database Design']=新阵列('DBDS1','DBDS2');
rolelevel['Systems Development and Maintenance']['Documentation/Technical Authoring']=新阵列('DOCM1','DOCM2');
rolelevel['Systems Development and Maintenance']['Porting/Software Integration']=新阵列('PORT2');
rolelevel['Systems Development and Maintenance']['Programming/Software Creation']=新阵列('PROG1','PROG2');
rolelevel[“系统开发和维护”][“安全工程”]=新阵列(“SFEN2”);
rolelevel['Systems Development and Maintenance']['Software Engineering']=新阵列('SENG1','SENG2');
rolelevel[“系统开发和维护”][“系统设计”]=新阵列(“DESN2”);
rolelevel['Systems Development and Maintenance']['Systems Integration']=新阵列('SIST1','SIST2');
rolelevel['Systems Development and Maintenance']['Software Testing']=新阵列('TEST1','TEST2');
rolelevel['Systems Development and Maintenance']['Web Site Specialism']=新阵列('WBSP1','WBSP2');
rolelevel['Service Delivery']=新数组();
rolelevel['Service Delivery']['Computer Operations']=新数组('COPS0','COPS1');
rolelevel['Service Delivery']['Database Administration']=新阵列('DBDS1','DBDS2');
rolelevel['Service Delivery']['Hardware/Software Installation']=新阵列('HSIN1','HSIN2');
rolelevel['Service Delivery']['Help Desk']=新数组('HELP0','HELP1','HELP2');
rolelevel['Service Delivery']['Installation and Implementation']=新阵列('INIM1','INIM2');
rolelevel['Service Delivery']['Network Administration and Support']=新阵列('NTAS2');
rolelevel['Service Delivery']['Network Operations']=new Array('NTOP0','NTOP1','NTOP2');
rolelevel['Service Delivery']['Service Level Monitoring']=新阵列('SLMO2');
rolelevel['Service Delivery']['User Support']=新阵列('USUP1','USUP2');
rolelevel['Technical Advice and Consultancy']=新阵列();
rolelevel[“技术建议和咨询”][“系统工效学评估”]=新阵列(“HCEV2”);
rolelevel['Quality']=新数组();
rolelevel['Quality']['Quality Standards']=新数组('QUST1','QUST2');
rolelevel['Customer Relations']=新数组();
rolelevel['Customer Relations']['Marketing']=新阵列('MKTG2');
rolelevel['Customer Relations']['Sales Support']=新阵列('SSUP1','SSUP2');
rolelevel['Education and Training']=新数组();
rolelevel[“教育和培训”][“教育”
        $.ajax({
            url: '../controller/getData',
            type: 'POST',
            success: function (data) {
                var aname = '';
                $("#firstDropdownlistID").twocolumnautocomplete2({
                    source: data,
                    minLength: 0,
                    valueFirst: true,
                    select: function (event, ui) {
                        //Set data to some field.
                        $("#field1").val(ui.item.label);
                        $("#fiedl2").val(ui.item.value);
                        // Fill data for dropdown 2 from selected value in dropdown 1
                        GetDataForDropDown2($("#fiedl2").val(ui.item.value));
                    },
                    change: function (event, ui) {
                        debugger;
                        if (ui.item == null) {
                            $("#field1").val(null);
                            $("#field2").val(null);
                        } else {
                            $("#field1").val(ui.item.label);
                            $("#field2").val(ui.item.value);
                        // Fill data for dropdown 2 from selected value in dropdown 1
                        GetDataForDropDown2($("#fiedl2").val(ui.item.value));
                        }
                    }
                }).focus(function () {
                    $(this).twocolumnautocomplete2("search", "");
                });
            }
        });
$.ajax({
            url: '../controller/getData',
            type: 'POST',
            success: function (data) {
                var aname = '';
                $("#firstDropdownlistID").twocolumnautocomplete2({
                    source: data,
                    minLength: 0,
                    valueFirst: true,
                    select: function (event, ui) {
                        //Set data to some field.
                        $("#field1").val(ui.item.label);
                        $("#fiedl2").val(ui.item.value);
                        // Fill data for dropdown 2 from selected value in dropdown 1
                        GetDataForDropDown3($("#fiedl2").val(ui.item.value));
                    },
                    change: function (event, ui) {
                        debugger;
                        if (ui.item == null) {
                            $("#field1").val(null);
                            $("#field2").val(null);
                        } else {
                            $("#field1").val(ui.item.label);
                            $("#field2").val(ui.item.value);
                        // Fill data for dropdown 2 from selected value in dropdown 1
                        GetDataForDropDown3($("#fiedl2").val(ui.item.value));
                        }
                    }
                }).focus(function () {
                    $(this).twocolumnautocomplete2("search", "");
                });
            }
        });
        var factory = CommonData.GetMsFactories();

        var factoryValue = factory.Select(s => new FactorySearchFactoryCode
                                                   {
                                                       ID = s.Id, 
                                                       FactoryCode = s.Code,
                                                       FactoryName = s.Value
                                                   }).ToList();
        dataoutput = factoryValue;
        return searchResult;
    }