How to check string contains certain word in client script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-21-2024 07:55 AM
Hi All,
I am having location and location type variables in 1 catalog item. Based on location variable, I need to set location type variable(remote, onsite) choices in select box.
I am writing an on change client script . Requirement is if location variable contains ex: Remote, AZ or Home Office(California), then the location type should appear as Remote
Any other selection, it should be Onsite.
But as per the below script, it is always going to Onsite . Please help me how it can be achieved
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-21-2024 08:11 AM
Hey @Renu9 ,
Please find the corrected version of your script:
var loc = g_form.getDisplayValue('location_emp').toLowerCase();
alert("loc is " + loc);
if (loc.includes('remote') || loc.includes('home office')) {
alert("into if");
g_form.setValue('location_type', 'Remote');
} else {
alert("into else");
g_form.setValue('location_type', 'Onsite');
}
If you find my response helpful, please consider marking it as the 'Accepted Solution' and giving it a 'Helpful' rating. Your feedback not only supports the community but also encourages me to continue providing valuable assistance.
Thanks,
Amitoj Wadhera