Onsubmit vs onchange function
Hi there,
I have a function which works perfectly fine onsubmit:
I need it to work on change though .... so i tried this:
and the subsring is not passed to the field.... Could you please help me and point out my mistake?
I have a function which works perfectly fine onsubmit:
Code: Select all
fd.onsubmit(function() {
var container = fd.field('Facility').control()._el().find('.ms-taxonomy').get(0);
var taxCtlObj = new Microsoft.SharePoint.Taxonomy.ControlObject(container);
var termValue = taxCtlObj.getRawText();
var str = termValue;
var res = str.substr(0,4)
fd.field('FacilityCheck').value(res);
return true
});
Code: Select all
function setFC() {
var container = fd.field('Facility').control()._el().find('.ms-taxonomy').get(0);
var taxCtlObj = new Microsoft.SharePoint.Taxonomy.ControlObject(container);
var termValue = taxCtlObj.getRawText();
var str = termValue;
var res = str.substr(0,4)
fd.field('FacilityCheck').value(res);
}
// Calling when the user changes plant .
fd.field('Facility').change(setFC);
// Calling on form loading
setFC();
- Nikita Kurguzov
- Posts: 889
- Joined: Mon Jul 03, 2017
Dear Katy,
Please, try to call function like this instead:
Please, try to call function like this instead:
Code: Select all
fd.field('Facility').change(function(){
setFC();
});
Cheers
- Nikita Kurguzov
- Posts: 889
- Joined: Mon Jul 03, 2017
Dear Katy,
There is no need to be sorry, it's okay
But it should work technically. There might be only a few reasons why it doesn't:
1) Incorrect InternalName of the field. Instead of 'Facility' it's something else. Please, check this in the designer when you select this field. You can also try:
2) This type of field doesn't support change event, like Taxonomy, for example, then you need to think of a different way to detect change, like an interval timer. For how to detect change in various fields, please, check out this - https://spform.com/javascript-framework ... eld-values
3) There is an error in the code, in this case you'll get a JS error in the browser's console on each change event.
P.S. Judging by the code it is Taxonomy field, isn't it? In this case the change won't fire, and I recommend using an interval timer instead - https://www.w3schools.com/jsref/met_win_setinterval.asp
Set an interval to about a 1000 or 2000. First, check if there is difference in value. If there is, run the setFC(); function.
There is no need to be sorry, it's okay

1) Incorrect InternalName of the field. Instead of 'Facility' it's something else. Please, check this in the designer when you select this field. You can also try:
Code: Select all
fd.field('Facility').change(function(){
alert('change');
});
3) There is an error in the code, in this case you'll get a JS error in the browser's console on each change event.
P.S. Judging by the code it is Taxonomy field, isn't it? In this case the change won't fire, and I recommend using an interval timer instead - https://www.w3schools.com/jsref/met_win_setinterval.asp
Set an interval to about a 1000 or 2000. First, check if there is difference in value. If there is, run the setFC(); function.
Cheers
-
- Information
-
Who is online
Users browsing this forum: No registered users and 6 guests