I have added the below code, But I am not able to retrieve the web or site. And added this script in Content editor web part of list. Can you please let me know where did I go wrong?
$(document).ready(function() {
$(ctl00_ctl34_g_9308082e_bd1c_4559_868d_9aa8eb1da6aa_ctl00_ctl05_ctl01_ctl00_ctl00_ctl04_ctl00_ctl00_UserField_checkNames).attr("onclick", "ValidateForm()");
});
function ValidateForm() {
var url = window.location.href;
var vars = url.split("=");
var ID = vars[1].split("&");
var ID1 = ID[0];
alert(ID1);
var context = new SP.ClientContext("http://siteName");
alert(context);
var web = context.get_web();
alert(web);
alert
var list = context.get_web().get_lists().getByTitle('ListName');
alert(list);
var camlQuery = new SP.CamlQuery();
camlQuery.set_viewXml("<View><Query><Where><Eq><FieldRef Name='ID'/><Value Type ='Text'>" + ID1 + "</Value></Eq></Where></Query></View>");
listitem = list.getItems(camlQuery);
alert(camlQuery);
alert(listitem);
context.load(listitem);
context.executeQueryAsync(Function.createDelegate(this, this.onSuccess), Function.createDelegate(this, this.onFailed));
}
function onSuccess(sender, args) {
var ListEnumerator = listitem.getEnumerator();
while (ListEnumerator.moverNext()) {
var currentItem = ListEnumerator.get_current();
var id = currentItem.get_item("ID");
alert(id);
}
}
function onFailed(sender, args) {
alert("error");
}
