- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-20-2020 04:37 AM
Hi Guys,
I have a email address field within a Catalog item.
I have created a an onChange catalog client script which checks if the email field is valid syntax and if not throws an error message at the top of the form.
Now that all works fine, but I want to either make the submit button greyed out / unavailable or the field to be kept mandatory until the client script conditions are met,
Because as it stands, users can enter an invalid email address syntax and still submit it!
Below is my code:
Many thanks,
Usmaan.
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-20-2020 04:51 AM
Hi,
Try onSubmit client script.
and add return false; in if condition after error message.
Thanks,
Dhananjay.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-20-2020 05:04 AM
Hi Usmaan,
As rightly suggested by others you need to use onSubmit instead of onChange()
Make sure you add return false; to the script to abort action.
Changing the Type to onSubmit will not work directly. You need to ensure that the onSubmit() function is used in client script.
In short, do below.
1. Change the Type to onSubmit
2. Replace first 5 lines of the script with below.
function onSubmit() {
3. Comment out last two '}'
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-20-2020 05:13 AM
Thanks all,
Changing to onSubmit has worked.
Below is the revised code:
function onSubmit() {
// This checks the email to ensure the names are seperated with a _ and the domain name is an exact match
var validRegExp = /^[a-zA-Z0-9]+(_)+[a-zA-Z0-9]+@(freshfields)\.com$/i;
var strEmail = g_form.getValue('team_email_address');
if (strEmail.search(validRegExp) == -1)
{
// This displays an error message at the top of the form in red
g_form.addErrorMessage('A valid e-mail address is required eg:location_name@freshfields.com.');
return false;
}
}
Thank you all for your help.
Regards.
Usmaan.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-20-2020 05:17 AM
Hi Usmaan,
Glad that you got the approach.
Did you mistakenly mark other answer as correct?
As I see same comments were provided before by other community members Dhananjay and myself.
You can only have one response marked as Correct.
Please consider marking appropriate reply as Correct & Helpful.
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-20-2020 05:22 AM
I believe the changes you have made is firstly provided/suggested by me, so I will appreciate if you mark my response as correct.
Thanks,
Dhananjay.