SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a lookup column with more than 20 items and I want to retrieve the selected text in a variable.To achieve this I have tried the code below but I am getting an error(mentioned in the code).

Note : When i use an alert, it is showing the correct value.

 var sys = null;
 var unit = null;

    sys = $("[title='Unit'] option:selected").text();
    unit = sys;
    sys += ' - ' + $("[title='System'] option:selected").text();
  else if(getField("input","Unit"))
     sys = getField("input","Unit");
     var opt=document.getElementById(sys.opt);
     **sys = opt.options[opt.selectedIndex].text;** // throws error Object does not support this action
     unit = sys;
     sys += ' - ' + $("[title='System'] option:selected").text();


share|improve this question
up vote 0 down vote accepted

To answer your questions i have created 2 list List1 has Country text column List2 has Country1 lookup columns which looks up Country Column from the List1

The lookup column is rendered as "select" when the items are less than 20 columns but it is rendered as "input" when the item are more than 20 items.

Below is the code you should paste in the content editor Webpart on the newform.aspx page. Update : I don't know how much efficient this approach is, its more like a work around for this situation.

alert( gives of id of the current lookupdropdown field which was clicked, so based on that you can have a if loop checking for the id- so then it would know which specific drop down box was clicked.

       <script src="yourpath/jquery-1.7.2.js" type="text/javascript"></script>
            <script type="text/javascript">
            $(document).ready(function() {

                  var oldset = _SetCtrlFromOpt; 

                  _SetCtrlFromOpt = function(ctrl, opt){ 

                        var s = opt.options[opt.selectedIndex].text;


                        oldset(ctrl, opt); 

 oldset(ctrl, opt); 

        if("id of other look up dropdown box")


The selected item from the drop down box gets displayed in the "SelectedCountry1" textbox. I have asked a similar kind of question months back here is the link Dropdown lookupcoloumn in sharepoint list form (newform.aspx)2010 You can refer to this link for excellent explanation.

share|improve this answer
Between i tried this approach as well and it is also working .. link – user9167 Jul 13 '12 at 12:25
Actually in ur approach i am facing one issue , say i have three to four Lookup columns in same page which has more than 20 items, if i implement the code you shared, all the controls in the form are showing same value on change ... please help – user9167 Jul 13 '12 at 12:51
Hi User9167- I have updated the answer. – spStacker Jul 13 '12 at 18:17
Hi , I am getting error that 'ctrl' is undefined .. if i do this way – user9167 Jul 16 '12 at 6:42
Hi User9167, sorry i am unable to check the code at my place, but i have updated it code, try it and see if it works for you – spStacker Jul 16 '12 at 13:48

Why don't you use InfoPath? I guess it would be easier.

share|improve this answer
Thanks for your reply. But we want to implement this only with jquery/javascript – user9167 Jul 11 '12 at 14:05

Your Answer


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

Not the answer you're looking for? Browse other questions tagged or ask your own question.