2012-01-13 46 views
-1

我如何改变价值ID,如果我键入输入文本不匹配? 下面的代码:如何改变value id如果我键入输入文本不匹配?

<script src="jquery-1.4.js"></script> 
<script type="text/javascript" src="jquery-1.3.2.min.js"></script> 
<script type="text/javascript" src="jquery.autocomplete.js"></script> 
<link rel="stylesheet" type="text/css" href="jquery.autocomplete.css" /> 
<script> 
$(document).ready(function() 
{ 
    $('[id^="participant"]').keyup(function() 
    { 
     var txt = $(this).val(); 
     $.ajax({ 
      type: "POST", 
      url: "blue.php", 
      data: "nameparticipant=" + txt, 
      contentType: "application/json; charset=utf-8", 
      dataType: "json", 
      success: function(data) 
      { 
       $(this).next().val(data.d); 
      }, 
      failure: failerEvent 
     }); 
    }); 
}); 
</script> 

这里是PHP代码:

<?php 
include"connection.php"; 
$nameparticipant=$_POST["nameparticipant"]); 
$res = mysql_query("select * from tabel where upper(name) like '$nameparticipant%'"); 
$t=mysql_fetch_array($res); 
echo "$t[id]"; 
?> 

这里的HTML正文:

<input type="text" id="participant1" name="name[1][]" value="Andi"/> 
<input type="text" id="idparticipant1" name="idparticipant[1][]" value="1001"/> 

<input type="text" id="participant2" name="name[2][]" value="Smith"/> 
<input type="text" id="idparticipant2" name="idparticipant[2][]" value="1005" /> 

我能做些什么?请帮我:(

+0

请帮助我:( – 2012-01-13 07:49:58

+0

你想做什么? – 2012-02-23 05:35:34

+0

如果我键入输入文本不匹配是什么意思? – 2012-02-23 05:41:52

回答

0

我不知道你正在尝试做的,但我看到很多的问题与您的代码。

首先,contentType: "application/json; charset=utf-8",,这是数据的内容类型发送服务器。你是不是发送JSON到服务器,因此不需要此行,将其删除。

其次,failure: failerEvent该选项error,不failure。它应该是error: failerEvent

三,echo "$t[id]";。在你的AJAX调用中,你说的是dataType: 'json',这意味着jQuery期望服务器输出JSON。我只能假设数据库表中的id字段实际上不是JSON字符串。你可能想要echo json_encode($t)

0

请详细解释一下您确切想要做什么,以及您的错误是什么?还有一个问题,为什么你在代码中使用两个jQuery?第1个jquery-1.4.js和第2个jquery-1.3.2.min.js。