0

var qString = null ; $(document).ready(function () { try { getDetails(); } catch(e) { alert("error occured at ready method" + e.message); } });

if(qString != null)
{

                $.ajax({  
                    url:  _spPageContextInfo.siteAbsoluteUrl + "/_api/web/lists/getbyTitle('My list')/items/?$select=Title&$filter=ID eq "+qString,                   
                    method: "GET",  
                    headers: { "Accept": "application/json; odata=verbose" },  
                    success: function (data)  
                    {  
            onSuccessResult(data);

            },
                error: function (data)  
                {  
                    $('body').html(data);  
                    console.log("error");  
                }  
            });
}


function onSuccessResult(data)
{
$.each(data.d.results, function(index, item){  
                            var title= (item["title"]); 
                $('#TitleId').val(title); });


  }
6
  • Use the code button in the editor to properly format your code, or add 4 leading spaces to every line... Then we might try to read your code.. And might I suggest you try to make it work yourself a bit harder before asking questions. Put a console statement inside the getdetails function and first investigate yourself What might be wrong. Apr 19 '16 at 9:49
  • functn not getting called
    – user52650
    Apr 19 '16 at 10:09
  • Now retrace your code back... WHY is it not called...Search for debugger; on Google and learn to debug. Programming is Work with capital W.. just like Sports (with capital S) you have to practice before you can perform Apr 19 '16 at 10:29
  • i m trying to find but cudn't figure this out...so i wud be grateful if u help me out
    – user52650
    Apr 20 '16 at 4:42
  • when i debug,i find that control reaches to if(qString != null) directly from document.ready without entering into loop and then o/p 1 is coming in console
    – user52650
    Apr 20 '16 at 6:36
0
qString= null;
$( document ).ready(function() { 
     var qString =  getdetails();

     if(qString != null)
    {
                $.ajax({  
                    url: _spPageContextInfo.siteAbsoluteUrl + "/_api/web/lists/getbyTitle('My list')/items/?$select=Title,Name,Age,DOB,Indian&$filter=ID eq "+qString,  


                    method: "GET",  
                    headers: { "Accept": "application/json; odata=verbose" },  
                    success: function (data)  
                    {  

            $.each(data.d.results, function(index, item){

                 var title  = item.Title; 
                 var name   = item.Name; 
                 var dob    = item.DOB;  
                 var age    = item.Age;
                 var indian = item.Indian ;
                 var address = item.Address;
                 document.getElementById('AddressId').value = strip(item.Address);
                 document.getElementById('DOBId').value = getDate(item.DOB);
                 $('#TitleId').val(title); 
                 $('#NameId').val(name);
                 $('#AgeId').val(age);
                // $('#DOBId').val(dob);
                 $('#IndianId').val(indian);
                                             });       
            },
                error: function (data)  
                {  

                    $('body').html(data);  
                    console.log("error"); 
                }  
            });
    }
});

function strip(html)
{
   console.log(html);
   var tmp = document.createElement("DIV");
   tmp.innerHTML = html;
   console.log("text" + tmp.textContent);
   console.log("html" + tmp.innerHtml);
   return tmp.textContent || tmp.innerText || "";
}
function getDate(stringDate)
{
  var todayTime = new Date(stringDate);

   return todayTime.toLocaleDateString();
}
function getdetails() 
{
   var result =  window.location.href.split("?ID=")[1];
  return result;
}
7
  • how to use " window.location.href.split("?ID=")[1]" in getdetails funcntn to split by id
    – user52650
    Apr 20 '16 at 9:33
  • Replace var result = 1; line with var result = window.location.href.split("?ID=")[1]; Apr 20 '16 at 9:35
  • Mark the answer for helpful to others Apr 20 '16 at 10:33
  • cn u tell me how to get username , lookup field and rich text in the same
    – user52650
    Apr 20 '16 at 10:41
  • I don't have idea but need to check it. Apr 20 '16 at 10:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.