How can I use JavaScript to set the value for Lookup Field in IE

Jun 24, 2009 at 1:14 AM

I have the following code in an edit form. I am trying to set the Lookup field's value property through JavaScript based on a value passed in from a Query String. When I attempt this code on FireFox, it works perfectly. However, in IE, the field does not show the text value I set.

If I try this code on another TextArea element, it works well even in IE. Its just the Object Picker TextArea that is causing a problem. Any suggestions?



<script language="javascript" type="text/javascript" >

function getField(fieldType,fieldTitle) { var docTags = document.getElementsByTagName(fieldType); for (var i=0; i < docTags.length; i++) { if (docTags[i].title == fieldTitle) { return docTags[i] } } } function populateRelatedContentID() { var fullURL = parent.document.URL; var xxx = fullURL.substring(fullURL.lastIndexOf('=')+1, fullURL.length); if(fullURL.lastIndexOf('=') == -1) { xxx = '(None)'; } try { var txtArea = getField('textarea','Object Picker'); txtArea.value = xxx; var txtArea2 = getField('textarea','Detailed Description'); txtArea2.value = xxx; } catch (e) { alert("An exception occurred in the script. Error name: " + + ". Error message: " + e.message); } document.body.focus(); } populateRelatedContentID(); </script>

Jun 25, 2009 at 12:16 PM


if you want to use JavaScript, I would recommend jQuery Works with all browsers and is just great. Take a look.

Preselecting an entity via query string should be work out of the box with my picker. You can configure in the field settings the name of the query string variable to look for and then you just need to provide an appropriate id with the query string and it should work.

Bye, Christian