0

When using jQuery, what is the syntax to set a lookup column to a value retrieved from another lookup column. I have been able to prepopulate a string column with a value retrieved from a lookup column, but am having trouble setting a lookup column to this value. How do I set the lookup column to the id of the value that the jQuery retrieved for me? Thank you.

2 Answers 2

1

Can you explain a little more? How are your lookup columns related?

If you take a look at my SPServices jQuery library, it may give you some clues. The way I read your question, you should probably just be setting to the text value, not bothering with the ID.

2
  • Hi Marc. Thank you for your response. The lookup columns are not related to each other, they are the same. I am trying to take the Divison that a particular employee belongs to (Stored in the User Information List) and prepopulate another Division lookup field on the NewForm.aspx with the same value. This value could be changed if necessary. I haven't been able to get it to work with the lookup column. I'm not trying to change the datasource in the lookup, just pre-select the value. It will put the correct value in a textbox, however. Thanks for your help.
    – Anonymous
    Commented Jul 26, 2010 at 18:48
  • Same answer as in your other post, I think: take a look at SPServices! Commented Jul 28, 2010 at 3:54
0

You can use the following:

 var selector="select[title=MyLookup]"; $(selector).val(newValue);

the newValue could be an ordinal of the option or the displayed text equivalent of the option.

HTH

3
  • Disclaimer: This is oversimplified as lookup UI renders and behaves differently for under-20- and more-than-20-options-lookups. Read Marc's blog or EUSP for more details. Commented Jul 26, 2010 at 19:13
  • Thank you AKrasheninnikov. It works fine when I use the ordinal of the option, however, I am not able to make it work with the text equivalent. I tried to hardcode the text equivalent as well. Do you know what I doing wrong? Thank you.
    – Anonymous
    Commented Jul 27, 2010 at 18:07
  • In my case it works like this $("td.ms-formbody select[title=Delivery status]").val("Shipped"), even when the actual "Delivery status" and "Shipped" are UTF-8 extended symbols. Make sure the value is exactly equal to the contents of the corresponding <option>option</option> Commented Jul 28, 2010 at 10:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.