3

I have a dropdown field which is a lookup containing values. I need to get the ID of the selected value whenever we change. I tried using the following. I didnt get any response

$ (document).ready(function(){

$("#ctl00_m_g_8c84c77a_5db3_4a23_9869_d6079afd3bd5_ctl00_ctl05_ctl01_ctl00_ctl00_ctl04_ctl00_Lookup").change(function() { alert("hi"); var id = $(this).find('option:selected').attr('id'); });

alert(id); });

4

The ID of the control will differ, try to use $("[id$='Lookup']") to get an element ending with "Lookup".

Then you can use .val() to get the selected value of the dropdown: var id= $("[id$='Lookup']").val();

  • thnks for the info – Arul Jul 15 '13 at 8:22
  • So, did it work or not? :P – Robert Lindgren Jul 15 '13 at 8:53
  • Then please please mark it as an answer – Robert Lindgren Jul 15 '13 at 10:33
3

That's correct as suggested by Robert. But just in case, if there are more than one look up columns add an extra filter as shown in the below script

<script type="text/javascript">
    $(document).ready(function () {
        if ($("[id$='_Lookup'][title='<<FieldName>>']").length > 0) {
            $("[id$='_Lookup'][title='<<FieldName>>']").change(function () {
                alert($("[id$='_Lookup'][title='<<FieldName>>']").val());
            });
        }
    });
</script>

Replace <<FieldName>> with your Field Title.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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