How to use retrieved SP list item in page text

Mar 2, 2013 at 12:12 PM
Edited Mar 2, 2013 at 12:13 PM
They say there are no stupid questions, so here goes. I'm a little fuzzy on how to use retrieved list items. In a CEWP, after I retrieve an item from a SP list and assign it to a var, is it possible then use it in directly in html? For example, if "5" is assigned to varMyNumber, can I construct a sentence on the page that uses it, for example, "<p>I have + varMyNumber + fingers on my left hand</p>"?
Mar 2, 2013 at 3:50 PM
Adapting from the GetListItems documentation here, you can do something like this:
<script type="text/javascript" src="filelink/jquery-1.7.2.min.js"></script>
<script type="text/javascript" src="filelink/jquery.SPServices-0.7.2.min.js"></script>
<script language="javascript" type="text/javascript">

$(document).ready(function() {
    operation: "GetListItems",
    async: false,
    listName: "YourList",
    CAMLViewFields: "<ViewFields><FieldRef Name='Fingers' /></ViewFields>",
    completefunc: function (xData, Status) {
      $(xData.responseXML).SPFilterNode("z:row").each(function() {
        var sentence = "I have " + $(this).attr("ows_Fingers") + " fingers on my left hand.";
<p id="putsentencehere"/>
Mar 2, 2013 at 4:52 PM
Excellent! Thanks very much.