This project has moved. For the latest updates, please go here.

Lookup column on NewForm.aspx

Nov 1, 2012 at 10:24 AM
Edited Nov 1, 2012 at 2:06 PM

Using WSS 3,  I am trying to set a value in a Lookup column whose valid entries contain spaces, such as "nnnnn AAA BBB CCC" etc.

Whenever I set the value, the displayed 'string' looks correct with the spaces included. However, when trying to save the record by pressing OK on NewForm.aspx, the value is rejected - "Value is not among the set of..." etc. The string is then shown with '+' characters where the spaces were.

I've tried '.replace' on the 'c_ref' source string using #160, &nbsp, %20 etc. but all fail in the same way.

function GetValueFromURL(queryParamName) {
    var queryParams = location.href.toQueryParams();
    if (queryParams != null && queryParams[queryParamName] != null) {
        return decodeURI(queryParams[queryParamName]);
    return null;

    try {
      var urlValue = GetValueFromURL('c_ref');
      if (null != urlValue) { SPUtility.GetSPField('Complainant Ref').SetValue(urlValue); }
      urlValue = GetValueFromURL('c_add');
      if (null != urlValue) { SPUtility.GetSPField('Address').SetValue(urlValue); }

    } catch (ex) {

UPDATE @ 14:02 

Changed the 'c_ref' update code as follows: -

        var urlValue = GetValueFromURL('c_ref');
        if (null != urlValue) { SPUtility.GetSPField('Complainant Ref').SetValue(unescape(urlValue).split('+').join(' ')); }

The problem still occurs the first time I press OK on NewForm.aspx, but it doesn't display the '+' characters.

However,  pressing OK again works...

Also, same behaviour is seen when using .replace instead of split / join.


Nov 1, 2012 at 11:17 PM

Hey Mark, I'll take a look and see if I can reproduce this.

Nov 1, 2012 at 11:43 PM


I haven't been able to repro the issue yet. Some questions..

  • Is your field a single or multi-select lookup field? Are there more than 20 items in the lookup list?
  • Can you give me an example of the URL? Specifically I'm interested in what the query parameters are. For example: "NewForm.aspx?c_ref=aa+bb+cc" versus "NewForm.aspx?c_ref=aa bb cc" or even "NewForm.aspx?c_ref=aa%20bb%20cc"
  • Have you tried replacing all instances of "+" with " " (space) in c_ref?

Hopefully we can get this working for you.


Nov 2, 2012 at 9:43 AM

Hi Kit,

It's a single select with about 80 items.

I've already tried the 3 forms of URL 'spacing', e.g. ' ', '+' & '%20', and have tried various combinations of .replace in c_ref.

Something else to note: -

If you drop down the list then the correct entry is highlighted and then, without 'touching' the list, just press OK and it saves correctly


Nov 2, 2012 at 1:04 PM

I'm able to reproduce this using a large lookup field. I'll see if I can figure out what is causing the issue in SPUtility.

Nov 2, 2012 at 1:54 PM


I think I figured out the issue. Lookup fields are weird because they change depending on which browser you are using.. autocomplete in IE and dropdown in other browsers.

I've attached a new version of SPUtility.js here: If you don't mind, can you test out the fix and let me know if it is working for you?


Nov 2, 2012 at 2:57 PM

Hi Kit,

Many thanks - you're a genius!

My code works correctly now, and will certainly improve the user 'experience'.

Best regards,