2012-04-22 57 views
-1

我有一個問題時使用jQuery和窗體。 例如1有一些患者編輯形式自動完成與jQuery的編輯窗體

<form> 
    <input type="text" name="patient_medic_record_number"> 
    <input type="text" name="name"> 
    <input type="text" name="address"> 
    <select name="sex"> 
     <option value="--SEX--"> 
     <option value="Male"> 
     <option value="Female"> 
    </select> 
</form> 

如何加載從MySQL數據庫數據,則自動完成的姓名,地址,性別,當我插入patient_medic_record_number。

+0

阿賈克斯是word – gpasci 2012-04-22 04:11:19

+1

那麼你有很長的路要走。我的建議是從jQuery基礎,DOM操作開始。 – Shekhar 2012-04-22 04:11:27

+0

jQuery自動完成可能會有幫助。 http://jqueryui.com/demos/autocomplete/ – tusar 2012-04-22 04:20:05

回答

1

好吧,您可以使用JQuery Ajax Method加載數據。

當你進入patient_medic_record_number必須使用其OnChange事件,以提高你的XmlHttpRequest是這樣的:

$("input[name=patient_medic_record_number]").change(function(){ 

     var num = $(this).val(); 

     $.ajax({ 
       type: "POST", 
       url: "YourPage.aspx/FillControl", 
       data: "{ 'id': '" + num + "' }", 
       contentType: "application/json; charset=utf-8", 
       dataType: "json", 
       success: function (data) { 

        $("#input[name=name]").val(data.d[0]); 
        $("#input[name=address]").val(data.d[1]); 
        $("#input[name=sex]").val(data.d[2]); 

      }); 
     }); 

}); 

,然後在你的代碼中使用此Web方法的背後返回JSON值:

[WebMethod] 
public static object[] FillControl(string id) 
{ 

    //Do something with id and etc 

    return new object[]{"Ali foroughi" , "No where" , "Male"}; 

} 

如果你想了解更多的細節評論我。

+0

阿里=>請給我的jQuery代碼發送和顯示數據的名稱,地址和性別字段... – 2012-04-22 06:33:38

+0

@DedyBlackLaBeneamata,我做到了 – 2012-04-22 10:19:25