2012-01-13 45 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。