0
<script type="text/javascript" src="/Style Library/functions/jquery-1.11.3.min.js"></script>
<script type="text/javascript">

        $(document).ready(function(){
        $('#ctl00_m_g_3b1a3698_a0fa_4283_bf23_e830e012a848_ff21_ctl00_ctl00_TextField').val("1501");
        });

        $('#ctl00_m_g_3b1a3698_a0fa_4283_bf23_e830e012a848_ff161_ctl00_Lookup').change(function() {
        var str = $('#ctl00_m_g_3b1a3698_a0fa_4283_bf23_e830e012a848_ff161_ctl00_Lookup: selected').text();
        $('#ctl00_m_g_3b1a3698_a0fa_4283_bf23_e830e012a848_ff21_ctl00_ctl00_TextField').val(str);
        })
        .change();
</script>

The above code is working partially. ready function works but the change function does not trigger. Any guidance please. The above code I am using in SharePoint NewForm.aspx page.

Zakir HC
  • 262
  • 2
  • 4
  • 18
  • 1
    First thing you need to use `ControlName.ClientID` instead of a large rendered id, and why do you call again `change()` in the end? you should need to add your change event in `document ready event` – Mirza Danish Baig May 20 '15 at 08:19

1 Answers1

0

I changed my code as per given in below reference link and now my code is working as expected. The change function is firing now and on change the value is set in textbox:

Jquery select change not firing

$(document.body).on('change','#ctl00_m_g_3b1a3698_a0fa_4283_bf23_e830e012a848_ff161_ctl00_Lookup',function(){

var str = $('#ctl00_m_g_3b1a3698_a0fa_4283_bf23_e830e012a848_ff161_ctl00_Lookup :selected').text();

$("#ctl00_m_g_3b1a3698_a0fa_4283_bf23_e830e012a848_ff21_ctl00_ctl00_TextField").val(str);    
});
Community
  • 1
  • 1
Zakir HC
  • 262
  • 2
  • 4
  • 18