如何根据第一个自动完成中选择的值动态更新其他人的自动完成值

时间:2019-10-02 06:47:27

标签: javascript php jquery mysql jquery-ui-autocomplete

我想根据在Mysql数据库中第一个文本框中选择的值来更新其他人的自动完成值,我有下面的jquery代码来从availabletags数组中更新值,但是我想从mysql数据库中获取数据,所以如何进行更改到这个jQuery代码..任何帮助将不胜感激。在此先感谢。

$(document).ready(function () {
 var availableTags = [
"Java",
"JavaScript",
"PHP"
];
$( "#tags" ).autocomplete({
source: availableTags,
select: function( event, ui ) {
    $( "#version" ).val('');
    //alert(ui.item.value);
    var selected_val = ui.item.value;        
    if(selected_val == "Java")
    {
        $( "#version" ).autocomplete({
            source: ['Java 3.1' ,'Java 3.2']
    });
} 
else if(selected_val == "PHP")
{
    $( "#version" ).autocomplete({
        source: ['PHP 5.3.1' ,'PHP 5.3.4']
    });
} 
else if(selected_val == "JavaScript")
{
    $( "#version" ).autocomplete({
        source: ['JavaScript 1.0' ,'JavaScript 2.5']
    });
  } 
 }    
 });
 });

html

<h4>Jquery-ui autocomplete. The "version" values will be updated based on 
the selection of the selection of "programming language"</h4>
<div class="ui-widget">
<label for="tags">Select programming language: </label>
<input id="tags"><small>Type like "j"</small>

<br>
<label for="tags">Select version: </label>
<input id="version">    
</div>

mysql

DROP TABLE IF EXISTS `languages`;
CREATE TABLE IF NOT EXISTS `languages` (
 `Prog_language` varchar(20) DEFAULT NULL,
 `version` varchar(20) DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

INSERT INTO `languages` (`Prog_language`, `version`) VALUES
('Java', 'Java 3.1'),
('Java', 'Java 3.2'),
('JavaScript', 'JavaScript 1.0'),
('JavaScript', 'JavaScript 2.5'),
('PHP', 'PHP 5.3.1'),
('PHP', 'PHP 5.3.4');

0 个答案:

没有答案