none
How to get value from Lookup Field on onchange event?

    Question

  • Hi,

    below is the code to get value from lookup field in listform in sharepoint 2010.

    ExecuteOrDelayUntilScriptLoaded(function(){

    var ctrl= $("input[title='Deliverable Type']");  var oldset = _SetCtrlFromOpt; _SetCtrlFromOpt = function(ctrl, opt){ alert("changed!"); oldset(ctrl, opt);

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

    // call the below function with the value passed.

    initialize(stext); }},"core.js");

    below line is to get lookup field in list form

    var ctrl= $("input[title='Deliverable Type']"); 

    in above line title is Title of Lookup Field.

    below is the line to get selected text

    sText= opt.options[opt.selectedIndex].text;

    thanks,

    gaurav

    Monday, February 24, 2014 7:16 PM

Answers

  • Hi,

    According to your post, my understanding is that you want to get value from lookup field on onchange event.

    We can use jQuery to achieve it, the following code for your reference:

    <script src="http://code.jquery.com/jquery-1.10.2.min.js" type="text/javascript"></script>
    <script type="text/javascript">
        $(function () {
            $("select[title='Deliverable Type']").change(function () {
                var value = $(this).find("option:selected").text();
            });
        });
    </script>

    Best Regards


    Dennis Guo
    TechNet Community Support

    Tuesday, February 25, 2014 5:13 AM
    Moderator