Wednesday, February 29, 2012

Article 7: How to search list item base on ID

1.        Create New list with name is Customer or can download at here
a.       Change field Title to Customer ID
b.      Create new fields:
Name: Single line of text
Address: Single line of text
c.       Create new items as follows:
2.       Open Sharepoint Designer 2010
a.       In Site Pages, create new page ASPX
b.      Name is SearchCustomer.aspx
c.       Design UI as follows:
d.      Code here
<table style="width: 50%">
                                <td>Customer ID:</td>
                                                <input id="txtCustomerID" type="text" />
                                <td>Customer Name:</td>
                                                <input id="txtCustomerName" type="text" /></td>
                                                <input id="txtCustomerAddress" type="text" /></td>
                                                <input id="btnSearch" type="button" value="Search" onclick="SearchCustomer();"/></td>
e.      Open Sharepoint site

3.       Start code
a.       Download 2 files jquery-1.4.2.js and jquery.SPServices-0.5.6 at here  and upload to Shared Documents on top level site.
b.      Attach 2 files .js to code html above close tag head
<script type="text/javascript" src="../Shared Documents/jquery-1.4.2.js"></script>
<script type="text/javascript" src="../Shared Documents/jquery.SPServices-0.5.6.js"></script>
c.       Code here
<script type="text/javascript">
var id="#txtCustomerID";
function SearchCustomer() {
            try {
                    operation: "GetListItems",
                                            async: false,
                                            listName: "Customer",
                    CAMLQuery: '<Query><Where><Eq><FieldRef Name="Title" /><Value Type="Text">'+
                    completefunc: function(xData, Status) {
                        $(xData.responseXML).find("z\\:row").each(function() {
            catch (e) { alert(e); }

4.       Save file and run on IE => OK
5.       Run on FireFox => OK
6.       Run on FireFox => not OK


Post a Comment