2012-04-22 56 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