1: <script type="text/javascript">
2:
3: // This javascript sets the default value of a lookup field identified
4: // by <<FIELD DISPLAY NAME>> to the value stored in the querysting variable
5: // identified by <<QUERYSTRING VARIABLE NAME>>
6:
7: // Customize this javascript by replacing <<FIELD DISPLAY NAME>> and
8: // <<QUERYSTRING VARIABLE NAME>> with appropriate values.
9: // Then just paste it into NewForm.aspx inside PlaceHolderMain
10:
11: _spBodyOnLoadFunctionNames.push("fillDefaultValues"); 12:
13: function fillDefaultValues() { 14: var qs = location.search.substring(1, location.search.length);
15: var args = qs.split("&"); 16: var vals = new Object();
17: for (var i=0; i < args.length; i++) { 18: var nameVal = args[i].split("="); 19: var temp = unescape(nameVal[1]).split('+'); 20: nameVal[1] = temp.join(' '); 21: vals[nameVal[0]] = nameVal[1];
22: }
23:
24: setLookupFromFieldName("<<FIELD DISPLAY NAME>>", vals["<<QUERYSTRING VARIABLE NAME>>"]); 25: }
26:
27: function setLookupFromFieldName(fieldName, value) { 28: if (value == undefined) return;
29: var theSelect = getTagFromIdentifierAndTitle("select","Lookup",fieldName); 30:
31: // if theSelect is null, it means that the target list has more than
32: // 20 items, and the Lookup is being rendered with an input element
33:
34: if (theSelect == null) { 35: var theInput = getTagFromIdentifierAndTitle("input","",fieldName); 36: ShowDropdown(theInput.id); //this function is provided by SharePoint
37:
38: var opt=document.getElementById(theInput.opt);
39:
40: setSelectedOption(opt, value);
41: OptLoseFocus(opt); //this function is provided by SharePoint
42: } else { 43: setSelectedOption(theSelect, value);
44: }
45: }
46:
47: function setSelectedOption(select, value) { 48: var opts = select.options;
49: var l = opts.length;
50: if (select == null) return;
51: for (var i=0; i < l; i++) { 52: if (opts[i].value == value) { 53: select.selectedIndex = i;
54: return true;
55: }
56: }
57: return false;
58: }
59:
60: function getTagFromIdentifierAndTitle(tagName, identifier, title) { 61: var len = identifier.length;
62: var tags = document.getElementsByTagName(tagName);
63: for (var i=0; i < tags.length; i++) { 64: var tempString = tags[i].id;
65: if (tags[i].title == title && (identifier == "" || tempString.indexOf(identifier)
66: == tempString.length - len)) { 67: return tags[i];
68: }
69: }
70: return null;
71: }
72:
73: </script>