skater coder

angela chng – Ruby on Rails / PHP web developer & skater girl in Singapore

  • blogabout stuff
  • aboutthis website
  • contactdrop a message

July 18, 2008
Posted by roadburn

Using Query String Variables to Populate SharePoint Form Fields

http://mdablog.spaces.live.com/blog/cns!B0C40902E1212960!623.entry

<script type="text/javascript">

_spBodyOnLoadFunctionNames.push("fillDefaultValues");

var vals = new Object();

var navBarHelpOverrideKey = "wssmain";

function fillDefaultValues() {
  var qs = location.search.substring(1, location.search.length);
  var args = qs.split("&");

  for (var i=0; i < args.length; i++) {
    var nameVal = args[i].split("=");
    var temp = unescape(nameVal[1]).split('+');
    nameVal[1] = temp.join(' ');
    vals[nameVal[0]] = nameVal[1];
  }
  setLookupFromFieldName("ProjectID", vals["ProjectID"]);
}

// setLookupFromFieldName: Set a form field value using its
//    fieldname to find it in the page
// Arguments:
//        fieldName:    The name of the list column
//        value:        Set the fieldName to this value
//
    function setLookupFromFieldName(fieldName, value) {
        if (value == undefined) return;
        var theInput = getTagFromIdentifierAndTitle("input","",fieldName);
        if(theInput != null) {
            theInput.value = value;
        }
    }

// getTagFromIdentifierAndTitle: Find a form field object using its tagName,
//     identifier, and title to find it in the page
// Arguments:
//        tagName:    The type of input field (input, select, etc.)
//        identifier:    The identifier for the instance of the fieldName
//                       (ff1, ff2, etc.)
//        title:        The title of the list column
//
    function getTagFromIdentifierAndTitle(tagName, identifier, title) {
        var len = identifier.length;
        var tags = document.getElementsByTagName(tagName);

        for (var i=0; i < tags.length; i++) {
            var tempString = tags[i].id;
            if (tags[i].title == title && (identifier == "" ||
                  tempString.indexOf(identifier) == tempString.length - len)) {
                return tags[i];
            }
        }
        return null;
    }

</script>

Leave a comment

Posted Under Uncategorized

No Comments Yet

You can be the first to comment!

Leave a comment

* = Required

  • CATEGORIES
    • Coding Tips
    • Food
    • Portfolio
    • Rails
    • Sharepoint
    • Wordpress

  • TAGS
    activities AD ADAM ajax architecture authentication bluehost books custom application custom form date design disk partition ECTS event id eventid moss forum guid hotfix iis imap keberos list id lists masterpage moss mysite profiles Rails rails 2.0 reporting services ruby Sharepoint sharepoint 2007 site templates site usage sql server 2005 time updates vhd virtual pc visual studio webparts workflow wss

Subscribe via RSS