Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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.

share|improve this question

2 Answers 2

up vote 1 down vote accepted

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.

share|improve this answer
    
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 Jul 26 '10 at 18:48
    
Same answer as in your other post, I think: take a look at SPServices! –  Marc D Anderson Jul 28 '10 at 3:54
    
Thank you Marc. –  Anonymous Jul 28 '10 at 16:33

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

share|improve this answer
    
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. –  Alexey Krasheninnikov Jul 26 '10 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 Jul 27 '10 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> –  Alexey Krasheninnikov Jul 28 '10 at 10:45
    
Thanks again AKrasheninnikov for your help. –  Anonymous Jul 28 '10 at 16:37

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.