Friday, 12 August 2016

InfoPath and Javascript - accessing fields

I have found that if you reference the complete form name  #ctl00_ctl40_g_e8523f46_e657_46ec_aa9d_f8a08c446642_FormControl0_V1_I1_PB27 that form name changes when you republish the form.

The begin of the form name is dynamic and end is referring to the field in the form.

ctl00_ctl40_g_e8523f46_e657_46ec_aa9d_f8a08c446642_FormControl0_V1_I1_PB27

Should be written like this
//clear department and phone
$('[id$="FormControl0_V1_I1_T26"]').val("");
 $('[id$="FormControl0_V1_I1_T7"]').val("");

Not like this
//clear department and phone
 $('#ctl00_ctl40_g_84777929_920a_480e_81b1_1f2f20724097_FormControl0_V1_I1_T26').val("");
 $('#ctl00_ctl40_g_84777929_920a_480e_81b1_1f2f20724097_FormControl0_V1_I1_T7').val("");


To get the field information you can use debugger in IE (F12) or Chrome.






No comments:

Post a Comment