Wednesday, July 31, 2013

Using JQuery in new form and edit form

Using jquery-1.8.2.min.js;

To get the instance of a control which does not have the title field in source view:(f12 view)

Criteria is a lookup field name and the client ID for that would be ctl00_m_g_0cf2a9f8_fc83_4e94_a96e_c4cb7d1d3e09_ctl00_ctl04_ctl09_ctl00_ctl00_ctl04_ctl00_BambooLookupPlus_x0028_1_x0029__x0020_Criteria. Using Client Id directly in the script is not recommended, so use the following syntax to get the Criteria field instance. Normally the ID value would have the field name suffixed.

//To get the field instance:
var criteria1field = $("[id$='Criteria']")[0];

//To disable field
$(criteria1field).attr('disabled', 'disabled');

//To enable field

//Change event for Issue Type field
 $(criteria1field).bind("change", function() { //code goes here });

//wait for 5 seconds
  // code goes here

}, 5000);

//Set Criteria  field width and style   

//Set lookup field value
$(criteria1field).val("This is a sample value");

//To get the value of field that has title field in source view
var Severity = $("input[Title='Severity']").val();