SP service code to Get the value from SharePoint List and and display another value based on drop down value selection
/ Function for getting commnets on page load from Photographer lis
$(document).ready(function() {
// Photographer #1
$('select[title="Photographer1"]').change(function(e) {
var selectedValue = $('select[title="Photographer1"] :selected').text();
$().SPServices({
operation: "GetListItems",
listName: "Photographers",
CAMLViewFields: "<ViewFields><FieldRef Name='Comments' /></ViewFields>",
CAMLQuery: "<Query><Where><Eq><FieldRef Name='Name'/><Value Type='Text'>"+selectedValue+"</Value></Eq></Where></Query>",
completefunc: function (xData, Status) {
//alert(Status);
$(xData.responseXML).SPFilterNode("z:row").each(function() {
//PremiereDate = $(this).attr("ows_PremiereDate");
var comments= $(this).attr("ows_Comments");
if(comments!= null)
{
document.getElementById('Label1').innerHTML = comments;
}
else
{
document.getElementById('Label1').innerHTML = "";
}
});
}
});
});
//2nd Photographer
$('select[title="Photographer2"]').change(function(e) {
var ph2= $('select[title="Photographer2"] :selected').text();
$().SPServices({
operation: "GetListItems",
listName: "Photographers",
CAMLViewFields: "<ViewFields><FieldRef Name='Comments' /></ViewFields>",
CAMLQuery: "<Query><Where><Eq><FieldRef Name='Name'/><Value Type='Text'>"+ph2+"</Value></Eq></Where></Query>",
completefunc: function (xData, Status) {
//alert(Status);
$(xData.responseXML).SPFilterNode("z:row").each(function() {
//PremiereDate = $(this).attr("ows_PremiereDate");
var comments2= $(this).attr("ows_Comments");
if(comments2!= null)
{
document.getElementById('Label2').innerHTML = comments2;
}
else
{
document.getElementById('Label2').innerHTML = "";
}
});
}
});
});
Comments
Post a Comment